Created
September 3, 2019 02:25
-
-
Save Patchyst/111fb9618dbef89dacd22df3d24c4828 to your computer and use it in GitHub Desktop.
XOR Encryption GUI part 1
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 pre_process(string): | |
string_ord = [] | |
binary_ord = [] | |
for c in string: | |
string_ord.append(ord(c)) | |
for i in string_ord: | |
binary_ord.append(bin(i)) | |
return binary_ord | |
def preprocess_key(string_key): | |
int_key = int(string_key) | |
binary_key = bin(int_key) | |
return binary_key | |
def xor_cipher(password_binary, binary_key): | |
cipher_list = [] | |
counter = 0 | |
for b in password_binary: | |
x = int(password_binary[counter], 2) | |
y = int(binary_key, 2) | |
cipher_list.append(x ^ y) | |
counter += 1 | |
return cipher_list | |
def conversion(binary_list): | |
string_list = [] | |
for i in binary_list: | |
string_list.append(chr(i)) | |
cipher_string = "".join(string_list) | |
return cipher_string | |
def encrypt(key,password): | |
cipher_object = conversion(xor_cipher(pre_process(password),preprocess_key(key))) | |
return cipher_object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment