From d43947e51f32139ad0244d09c4b4086603f79325 Mon Sep 17 00:00:00 2001 From: Bucchino Geoffrey Date: Wed, 22 Jun 2022 21:27:56 +0200 Subject: [PATCH] Update code --- main.py | 31 ++++++++++++++++++++++++------- test.txt.crypt | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 554951d..f4d4cdb 100644 --- a/main.py +++ b/main.py @@ -63,13 +63,30 @@ def decryptCaesarText(cipherFile): if cipherFile is None: return - #for lines in cipherFile: - # splitLines = lines.split(' ') - - # for word in splitLines: - # if len(word) <= 3: - # print(word) - + letterAToAscii = ord('A') # Get the ASCII code + letterZToAscii = ord('Z') # Get the ASCII code + letteraToAscii = ord('a') # Get the ASCII code + letterzToAscii = ord('z') # Get the ASCII code + for key in range (0, 26): + foo = [] + for line in cipherFile: + newLine = str() + for letter in line: + letter = letter.upper() + l = ord(letter) + if l >= letterAToAscii and l <= letterZToAscii: + l = l - letterAToAscii + res = ((l - key) % 26) + letterAToAscii + newLine = newLine + chr(res) + elif l >= letteraToAscii and l <= letterzToAscii: + l = l - letteraToAscii + res = ((l - key) % 26) + letteraToAscii + newLine = newLine + chr(res) + else: + newLine = newLine + letter + foo.append(newLine) + print(f"key: {key}") + print(foo) if __name__ == "__main__": main() diff --git a/test.txt.crypt b/test.txt.crypt index b57a8a0..4ff5606 100644 --- a/test.txt.crypt +++ b/test.txt.crypt @@ -1,2 +1,2 @@ -AJGNNQ YQTNF! +JGNNQ YQTNF! LG UWKU WP OGUUCIG GP ENCKT !!