

Task

Implement a Caesar cipher, both encoding and decoding. 

The key is an integer from 1 to 25.

This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).

The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).

So key 2 encrypts "HI" to "JK", but key 20 encrypts "HI" to "BC".

This simple "mono-alphabetic substitution cipher" provides almost no security, because an attacker who has the encoded message can either use frequency analysis to guess the key, or just try all 25 keys.

Caesar cipher is identical to Vigenère cipher with a key of length 1. 

Also, Rot-13 is identical to Caesar cipher with key 13.



Related tasks

 Rot-13
 Substitution Cipher
 Vigenère Cipher/Cryptanalysis


00101000000000100000000000000000   0. -20 to c
11001000000000010000000000000000   1. Sub. 19
10101000000001100000000000000000   2. c to 21
10101000000000100000000000000000   3. -21 to c
00000000000000110000000000000000   4. Test
10001000000000000000000000000000   5. 17 to CI
10101000000001100000000000000000   6. c to 21
10101000000000100000000000000000   7. -21 to c
01001000000000010000000000000000   8. Sub. 18
10101000000001100000000000000000   9. c to 21
10101000000000100000000000000000  10. -21 to c
00000000000001110000000000000000  11. Stop
01001000000000010000000000000000  12. Sub. 18
00000000000000110000000000000000  13. Test
00000000000001110000000000000000  14. Stop
10101000000000100000000000000000  15. -21 to c
00000000000001110000000000000000  16. Stop
11010000000000000000000000000000  17. 11
01011000000000000000000000000000  18. 26