Cipher
InterviewTime limit2sMemory limit512 MB
Decrypt a Caesar-shifted message by trying all 26 shifts and picking the one where both CHIPMUNKS and LIVE appear.
- Level
Easy2 of 10
- Topics
- Brute force, String
- Solved
- No attempts yet
Problem
You lead a crack intelligence unit. Today your team intercepted a set of encrypted messages from Kojak, a well known and much feared terrorist leader. The ciphertexts are thought to carry instructions to his henchmen about which targets to attack next.
Kojak is careful about most things, but his cipher is a plain Caesar cipher. Every letter moves forward by a fixed number of positions , and is unknown to you. is an integer between and , so a message may also arrive unshifted. With the key is this:
So HELLO WORLD is encrypted to JGNNQ YQTNF. Kojak encrypts only uppercase letters and leaves lowercase letters, digits, spaces and punctuation as they are.
Your team also knows that the words CHIPMUNKS and LIVE always appear in Kojak's messages, and that he uses a different key for each message. You can assume that for each message, exactly one key makes both words appear in the decrypted text. Write a program that decrypts an intercepted message.
Input
One line holding the ciphertext. The line is at most 1,000 characters long.
Output
Print the plaintext version of the ciphertext. It consists of exactly the same characters as the ciphertext, newlines and spaces included, except that uppercase letters are replaced by their decrypted version.