Under construction

Still being built. Things may change

Attack of the CipherTexts

Interview

Time limit1sMemory limit128 MB

Summary
Given one plaintext/ciphertext pair, invert the letter substitution to decrypt a second ciphertext, printing a period for undetermined characters.
Level

Medium4 of 10

Topics
Hash map, String, Implementation
Solved
No attempts yet

Problem

Ruby is a code-breaker. She knows that two dangerous people, Mr. X and Mr. Z, are sending secret messages to each other about very bad things.

Ruby has intercepted one plaintext message together with its corresponding ciphertext. The plaintext is the original, readable message; the ciphertext is the encrypted, scrambled version. To encrypt a message, every letter is replaced by another letter so that the ciphertext does not reveal the plaintext.

Ruby knows the algorithm Mr. X and Mr. Z use: each character is mapped to exactly one other character. The mapping is a bijection — it is one-to-one (each plaintext character corresponds to exactly one ciphertext character) and onto (each ciphertext character corresponds to exactly one plaintext character).

Using the known plaintext/ciphertext pair, decrypt a second ciphertext message and help Ruby save the world.

Input

The input consists of three strings, one per line:

  • The first line is the plaintext message that Ruby already knows.
  • The second line is the ciphertext that corresponds to that plaintext (it has the same length as the first line).
  • The third line is a second ciphertext message that you must decrypt.

Every string has length between 1 and 80 characters. Only 27 characters are valid: the uppercase letters A through Z and the space character ( ). There are no lowercase letters, digits, punctuation, or other special characters.

Output

Print the plaintext string that corresponds to the third line (the second ciphertext).

Some characters of the third line may be impossible to determine, because the mapping for that ciphertext character never appears in the known plaintext/ciphertext pair. For every such character, print a period (.) in its place.

Examples2

  1. Example 1

    Input
    THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
    UIFARVJDLACSPXOAGPYAKVNQTAPWFSAUIFAMB ZAEPH
    XFABSFAWFSZACBEAQFPQMFAEPJOHAWFSZACBEAUIJOHTAIBAIB
    
    Expected output
    WE ARE VERY BAD PEOPLE DOING VERY BAD THINGS HA HA
    
  2. Example 2

    Input
    THERE ARE NOT ENOUGH LETTERS
    XQAZASEZASNYXSANYLWQSTAXXAZM
    JSCENNYXSIACYIASXQJM
    
    Expected output
    . .ANNOT .E.O.E TH.S