Caesar cipher

Useful to know: loops, strings.

Ever since ancient civilizations could write letter to each other, people have wanted to keep some messages secret in case they were intercepted by someone else. To do this, they used an encryption scheme or secret code to encrypt their message before sending it. The receiver could then decrypt it and read it if they knew how to decrypt it. In cryptography the original unencrypted message is called the plaintext (usually shown in all lowercase) while the encrypted message is the ciphertext (SHOWN IN ALL UPPERCASE).

A Caesar cipher using a right shift of 3 (which is the same as a left shift of -23). (Wikimedia Commons)

A famous method of encrypting a message is the Caesar cipher. It involves using a shifted alphabet instead of the regular alphabet. For example, a shift of 13 will involve changing A to N, B to O, C to P, and so on. It is a very weak cipher that provides no security nowadays but was actually secure at the time when no one knew of cryptography.

If you knew even a single word that is present in the ciphertext, that would be enough to break the caesar cipher and reveal the secret message. Given the ciphertext and a word that definitely exists in the plaintext, return the plaintext message.

Input: The ciphertext to be decrypted, and one word that present in the ciphertext.

Output: The original message in lower case letters.

Example input


Example output

"the quick brown fox jumped over the lazy dog"

You must be logged in to submit code but you can play around with the editor.

You must be logged in to upload code.


  • It's named after the Roman general and politician Julius Caesar (100-44 BC) who used it to secure military communications.
  • The shift of 13 given in the description corresponds to ROT13.