shift = 3
encrypted_text = open("book.txt", "r", encoding="utf-8")
plain_text = ""
for c in encrypted_text:
if c.isupper():
c_unicode = ord(c)
c_index = ord(c) - ord("A")
new_index = (c_index - shift) % 26
new_unicode = new_index + ord("A")
new_character = chr(new_unicode)
plain_text = plain_text + new_character
else:
plain_text += c
encrypted_text.close()
print("Decrypted text:", plain_text)
Asked
Active
Viewed 89 times
0
-
Please update your question with the full error traceback. – quamrana Sep 24 '21 at 16:28
-
1`c` will return a line at a time, not a character. You probably want `for c in encrypted_text.read()` – match Sep 24 '21 at 16:29
-
It's no longer giving me an error anymore but when I run it and it prints the text it just prints the encrypted text still – John Sep 24 '21 at 16:42