Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created August 10, 2022 14:50
Show Gist options
  • Save wesleyit/f06e7017116a89f44f061c712445015d to your computer and use it in GitHub Desktop.
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
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