Welcome to Project Lovelace! We're still super new so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or any comments at all please let us know on Discourse!

Caesar cipher

You will learn about: loops, strings.

Ever since ancient civilizations could write letters 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 is present in the plaintext.

Output: The original message in lower case letters.


Example

Input ciphertext: "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD" Input word: "fox" ─────────────────────────────────────────────────────────────── Output plaintext: "the quick brown fox jumps over the lazy dog"


 Difficulty  Timesink
 Maximum runtime 60 s  Max. memory usage 250 MiB
 Function signature break_caesar_cipher(ciphertext, known_word)

Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.




You must be logged in to view your submissions.

Notes

  • The Caesar cipher is named after the Roman general and politician Julius Caesar (100-44 BC) who used it to secure military communications. He may or may not have been the first to use this kind of substitution cipher, but his writings survive to the present day and give the earliest example so it's named after him.
  • The shift of 13 given in the input example corresponds to ROT13 which uses a shift of 13 to both encrypt and decrypt, which works as there are 26 letters in the English alphabet.

References

The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography, Simon Singh (2000)
Chapter 1 discusses the Caesar cipher. The rest of the book is an excellent historical account of cryptography.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able view the discussion thread below. Feel free to post your solutions but please do your best to organize and document your code well so others can learn from it.