e3c183d06a4017f0bb504de54c1f053178b56cae
3 def caesar_encipher_letter(letter
, shift
):
4 """Encipher a letter, given a shift amount
6 >>> caesar_encipher_letter('a', 1)
8 >>> caesar_encipher_letter('a', 2)
10 >>> caesar_encipher_letter('b', 2)
12 >>> caesar_encipher_letter('x', 2)
14 >>> caesar_encipher_letter('y', 2)
16 >>> caesar_encipher_letter('z', 2)
18 >>> caesar_encipher_letter('z', -1)
20 >>> caesar_encipher_letter('a', -1)
23 if letter
in string
.ascii_letters
:
24 if letter
in string
.ascii_uppercase
:
25 alphabet_start
= ord('A')
27 alphabet_start
= ord('a')
28 return chr(((ord(letter
) - alphabet_start
+ shift
) % 26) +
33 def caesar_decipher_letter(letter
, shift
):
34 """Decipher a letter, given a shift amount
36 >>> caesar_decipher_letter('b', 1)
38 >>> caesar_decipher_letter('b', 2)
41 return caesar_encipher_letter(letter
, -shift
)
43 def caesar_encipher(message
, shift
):
44 """Encipher a message with the Caesar cipher of given shift
46 >>> caesar_encipher('abc', 1)
48 >>> caesar_encipher('abc', 2)
50 >>> caesar_encipher('abcxyz', 2)
52 >>> caesar_encipher('ab cx yz', 2)
55 enciphered
= [caesar_encipher_letter(l
, shift
) for l
in message
]
56 return ''.join(enciphered
)
58 def caesar_decipher(message
, shift
):
59 """Decipher a message with the Caesar cipher of given shift
61 >>> caesar_decipher('bcd', 1)
63 >>> caesar_decipher('cde', 2)
65 >>> caesar_decipher('cd ez ab', 2)
68 return caesar_encipher(message
, -shift
)
71 if __name__
== "__main__":