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