A Caesar cipher, or a shift cipher, is one of the most well known encryption techniques. It works by substituting the letters in the message with letters some fixed number of positions down the alphabet.
Your challenge is to write a function that will accept a string and a shift key. It will return the encrypted text. If something in the string is not in the alphabet (e.g. punctuation, spaces) leave it as is.
plain: defend the east wall of the castle
cipher: efgfoe uif fbtu xbmm pg uif dbtumf
Write a function that will crack the cipher without knowing the shift. The shift key can only be in range of [1, 26].
cipher: dwwdfn iurp wkh zrrgv dw gdzq
plain: attack from the woods at dawn
I've used the brute-force method before (printing every possible key and manually searching for the right one). I can't wait to see other solutions to cracking this easy cipher.
Want to propose a challenge for a future post? Email firstname.lastname@example.org with your suggestions!