Sort of stumped here, can't find out how to undo the process done in the selection for "E" in "D". option D is supposed to decrypt while option E encrypts. Option E works as intended, but I can't figure out how I would undo it.
Selection = input('Are you decrypting or encrypting a file? Type E for encrypt, or D for decrypt\n')
if Selection == "E":
f = open('HolocronMessage.txt','r')
JediMessage = readLinesFromFile()
#print(JediMessage) -- LOL DEBUG
JediEncrypted = ""
for i in JediMessage:
JediEncrypted += chr(ord(i) - 3)
JediMessage = ''.join(format(ord(i), '08b') for i in JediEncrypted)
with open('HolocronMessage.txt', 'w') as f:
f.write(JediMessage)
print(JediMessage)
elif Selection == "D":
f = open('HolocronMessage.txt','r')
JediMessage = readLinesFromFile()
JediDecrypted = ""
for i in JediMessage:
JediDecrypted += chr(ord(i) + 3)
JediMessage = ''.join(format(ord(i), '08b') for i in JediDecrypted)
with open('HolocronMessage.txt', 'w') as f:
f.write(JediMessage)
else:
print("Invalid selection. Please return a valid seleciton.")
I am trying to make a decryption function starting at line 24 where the text file that was written is undone and the original message is returned.
I assume it has to do with changing line 30 with its inverse?
JediMessage = ''.join(format(ord(i), '08b')