30 lines
917 B
Python
30 lines
917 B
Python
def decode_token(username, token, masterpassword):
|
|
|
|
# decode the token from hex to bytes
|
|
decoded_token = bytes.fromhex(token)
|
|
|
|
unsername_from_token = bytearray()
|
|
for i in range(32):
|
|
unsername_from_token.append(decoded_token[i] ^ ord(masterpassword[i]))
|
|
|
|
# remove padding
|
|
unsername_from_token = unsername_from_token.rstrip(':'.encode())
|
|
print("Username from token:", unsername_from_token.decode())
|
|
|
|
return unsername_from_token.decode() == username
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
token = input("Enter your token: ")
|
|
username = input("Enter your username: ")
|
|
masterpassword = input("Enter your masterpassword (32 characters): ")
|
|
if len(masterpassword) != 32:
|
|
print("Masterpassword must be 32 characters long")
|
|
exit(1)
|
|
|
|
if decode_token(username, token, masterpassword):
|
|
print("Token is valid")
|
|
else:
|
|
print("Token is invalid")
|