From 078760393af3f608635a77e979b840c0249cc094 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Sat, 23 Sep 2023 23:56:03 -0400 Subject: [PATCH] done --- 05-caesar-cipher/caesar.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/05-caesar-cipher/caesar.py b/05-caesar-cipher/caesar.py index 2452c2a..80eb5e3 100644 --- a/05-caesar-cipher/caesar.py +++ b/05-caesar-cipher/caesar.py @@ -1,9 +1,24 @@ +def char_shift(char, shift): + start = 65 if char.isupper() else 97 + char = ord(char) - start + shift = (char + shift) % 26 + return chr(shift+start) + def caesar(message, shift): - pass + out = '' + for letter in message: + if letter.isalpha(): + letter = char_shift(letter, shift) + out += letter + return out +def decrypt_caesar(message, shift): + return caesar(message, shift - (shift*2)) +# Add your own assert statements to test your code. +sentence = 'But the Caesar Cipher is [still used](http://en.wikipedia.org/wiki/ROT13)' +shift = 300 - -# Add your own assert statements to test your code. \ No newline at end of file +assert(decrypt_caesar(caesar(sentence, shift), 300) == sentence ) \ No newline at end of file