T
T
Ternick2018-09-22 11:41:20
Python
Ternick, 2018-09-22 11:41:20

Function not working! (base64) (Cryptography) How to fix it?

Here is the function itself:

def VALIDATOR_KEY():
  global FILE_NAME
  with open(FILE_NAME, "r") as fn:
    TRUE_KEY_DECODING_STEP_ONE = fn.read()
    TRUE_KEY_DECODING_STEP_TWO = base64.b64decode(TRUE_KEY_DECODING_STEP_ONE)
  INPUT_KEY = input("Введите ключ для активации программы !" + "\n")
  TRUE_KEY = TRUE_KEY_DECODING_STEP_TWO.decode()
  if TRUE_KEY == INPUT_KEY:
    input("Программа ативирована удачно !")
  else:
    input("Попробуйте ещё раз !")
    VALIDATOR_KEY()

Here is the error:
C:\Users\User\Desktop\Python>py 1.py
Enter the key to activate the program!
XXX-XXX-XXX
Traceback (most recent call last):
File "1.py", line 42, in
main()
File "1.py", line 36, in main
VALIDATOR_KEY()
File "1.py", line 23, in VALIDATOR_KEY
TRUE_KEY = TRUE_KEY_DECODING_STEP_TWO.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 4: invalid start byte

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-09-22
@Ternick

Windows has a specific relationship with encoding, so it's better to use wb when writing
AND, in my opinion, when reading too

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question