Add example decode token funktion

This commit is contained in:
sebivh
2025-10-17 14:02:17 +02:00
parent 1115b7378f
commit 690696b496

29
dec_token.py Normal file
View File

@@ -0,0 +1,29 @@
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")