Add example tocken encryption pyhton function
This commit is contained in:
26
token.py
Normal file
26
token.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Function that generates a token depending on unsername and masterpassword
|
||||
# The masterpassword must be 32 characters long!
|
||||
def create_token(username, masterpassword):
|
||||
|
||||
if len(masterpassword) != 32:
|
||||
print("Masterpassword must be 32 characters long")
|
||||
exit(1)
|
||||
|
||||
padded_username = username.ljust(32, ':')
|
||||
|
||||
token = bytearray()
|
||||
# xor connect with masterpassword to create token
|
||||
for i in range(32):
|
||||
token.append(ord(padded_username[i]) ^ ord(masterpassword[i]))
|
||||
|
||||
str_token = token.hex()
|
||||
return str_token
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# request username and masterpassword
|
||||
username = input("Enter your username: ")
|
||||
masterpassword = input("Enter your masterpassword (32 characters): ")
|
||||
|
||||
token = create_token(username, masterpassword)
|
||||
print("Your token is: " + token)
|
||||
Reference in New Issue
Block a user