Created
August 10, 2022 14:50
-
-
Save wesleyit/f06e7017116a89f44f061c712445015d to your computer and use it in GitHub Desktop.
This is a simple implementation of the XOR encrypting/decrypting algorithm in python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt(message: str, key: str) -> str: | |
cipher = [] | |
for m, k in zip(message, key): | |
cipher += [hex(ord(m) ^ ord(k))] | |
return " ".join(cipher) | |
def decrypt(cipher: str, key: str) -> str: | |
message = "" | |
cipher = cipher.split(" ") | |
for c, k in zip(cipher, key): | |
message += chr(int(c, base=16) ^ ord(k)) | |
return message | |
encrypt('Wesley', 'AAAAAA') | |
# '0x16 0x24 0x32 0x2d 0x24 0x38' | |
decrypt('0x16 0x24 0x32 0x2d 0x24 0x38', 'AAAAAA') | |
# 'Wesley' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment