Under construction

Still being built. Things may change

Enigma

Interview

Time limit1sMemory limit256 MB

Summary
Implement a simplified Enigma machine whose two rotors advance together after each letter, and decrypt the given uppercase ciphertext using the rotor setting CHICKENS.
Level

Medium4 of 10

Topics
Simulation, Implementation, String, Math
Solved
No attempts yet

Problem

Jeongsang, who runs an antique shop, wanted chicken so badly one day that while his father was away on a long overseas business trip, he sold off his father's treasured Enigma machine and bought chicken with the money. Then his father found a secret ciphertext belonging to a secret German organization abroad and emailed him to decipher its contents. Since Jeongsang has no money and cannot get the Enigma machine back, he decides to implement the Enigma machine in code. Decipher the Enigma cipher his father sent.

The rotor setting of the ciphertext is "CHICKENS", and the ciphertext consists of uppercase letters and is at most 100 characters long.

The Enigma machine works as follows.

  • There are rotors inscribed with the alphabet from A to Z.
  • Given the initial rotor setting CE, when the alphabet string AB is entered:
  1. The first rotor is the rotor starting with C, and the given A is the first letter of the alphabet, so the first value C of the first rotor is returned.
  2. The second rotor is the rotor starting with E, and the given C is the third letter of the alphabet, so the third value G of the second rotor is returned.
  3. After the last rotor's return value G is returned, the conversion for the first character ends and the rotor setting changes to DE.
  4. For the second alphabet letter B, the first rotor is the rotor starting with D, and the given B is the second letter of the alphabet, so the second value E of the first rotor is returned.
  5. The second rotor is the rotor starting with E, and the given E is the fifth letter of the alphabet, so the fifth value I of the second rotor is returned.
  6. After the last rotor's return value I is returned, the conversion for the second character ends and the rotor setting changes to EE.

This is shown in the figure below.

Input

The first line gives a cipher string consisting of uppercase letters. The length of the cipher string is at most 100.

Output

Print the decrypted string on the first line.

Examples1

  1. Example 1

    Input
    KVZEOAQZITQLPHJNFKOIIP
    
    Expected output
    WINTERISCOMINGJOHNSNOW