Last active
February 5, 2020 04:41
-
-
Save davidlares/e8c92eb47ee747c83e6259151ad393d7 to your computer and use it in GitHub Desktop.
An isolated Python 2.x script for performing a basic XOR encryption for hard-coded data
This file contains hidden or 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
#!/usr/bin/python | |
import string | |
import random | |
# this will generate a random key used for the XOR encrpytion for 1kb = same as the TCP socket size | |
key = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits '^!\$%&/()=?{[]}+~#-_.:,;<>|\\') for _ in range(1024)) | |
# printing data | |
print(key) | |
print('\n' + 'Key length' + str(len(key))) | |
# XOR encryption should be gt the length of the message | |
message = 'ipconfig' | |
print("Hardcoded message is: " + message + "\n") | |
def str_xor(message, key): | |
# split the message abd the XOR key in a tuple format - each tuple is converted in to an integer value (ord) - no we perform exclusive XOR on them - merge the result on ASCII - finally join them | |
return "".join([chr(ord(c1) ^ ord(c2)) for (c1,c2) in zip(message,key)]) | |
# implemented methods with the same key | |
encryption = str_xor(message, key) | |
print('Encrypted message: ' + encryption + "\n") | |
decryption = str_xor(encrypted, key) | |
print('Decrypted message: ' + decryption + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment