I am trying to write a program to decrypt an XOR cipher with a key that has multiple characters in python and then print it out. This is my main file:
from crypto import decrypt
if __name__ == "__main__":
INTERCEPT_1="UDAXIHHEXDVXRCSNBACGHQTARGWUWRNHOSIZAYZFWNKIEGYKDCMDLLTIZBXORDMCRJUTLSGWCBVHYJCHDMIOULFL"
INTERCEPT_2 =";!7=;h/*6*7x5*%+b8,2h$$mr)2#2 n/ =';a5?2w7$<e#6<*om*):1;z%7!<%m1'$u5><29'b7&=j'-7(;;u5)9"
for i in range(len(INTERCEPT_1)):
print(INTERCEPT_1, INTERCEPT_2)
print(decrypt(INTERCEPT_1, INTERCEPT_2))
My crypto file:
from functions import or
def encrypt(message, key):
encrypted = ''
for character in message:
encrypted = encrypted + xor(character, key)
return encrypted
def decrypt(message, key):
return encrypt(message, key)
And my functions file:
def xor(character, key):
code = ord(character) ^ ord(key)
character = chr(code)
return character
I get this error:
Traceback (most recent call last):
File "program.py", line 11, in <module>
print(decrypt(INTERCEPT_1, INTERCEPT_2))
File "/tmp/tmpZ59DTD/crypto.py", line 10, in decrypt
return encrypt(message, key)
File "/tmp/tmpZ59DTD/crypto.py", line 6, in encrypt
encrypted = encrypted + xor(character, key)
File "/tmp/tmpZ59DTD/functions.py", line 2, in xor
code = ord(character) ^ ord(key)
TypeError: ord() expected a character, but string of length 88 found
How should I fix this? Any help is appreciated, thank you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…