Created as a part of MITx: 6.00.1x Introduction to Computer Science and Programming Using Python.
The idea of the Caesar Cipher is to pick an integer and shift every letter of your message by that integer. In other words, suppose the shift is k . Then, all instances of the i-th letter of the alphabet that appear in the plaintext should become the (i+k)-th letter of the alphabet in the ciphertext. You will need to be careful with the case in which i + k > 26 (the length of the alphabet). Here is what the whole alphabet looks like shifted three spots to the right:
Original: a b c d e f g h i j k l m n o p q r s t u v w x y z 3-shift: d e f g h i j k l m n o p q r s t u v w x y z a b c Using the above key, we can quickly translate the message "happy" to "kdssb" (note how the 3-shifted alphabet wraps around at the end, so x -> a, y -> b, and z -> c)
plaintext | shift | ciphertext |
---|---|---|
'abcdef' | 2 | 'cdefgh' |
'Hello, World!' | 5 | 'Mjqqt, Btwqi!' |
'' | any value | '' |