Playfair Cipher#550

Playfair Cipher

1 second
64 megabytes
Medium

The Playfair cipher is a manual symmetric encryption technique and was the first digraph substitution cipher. The scheme was invented in by Charles Wheatstone, but it is named after Lord Playfair, who promoted its use.

The Playfair cipher uses a 5 \times 5 table containing each letter in the English alphabet exactly once, except for , which is omitted. This table is the encryption key. To facilitate memorization, the table is usually generated from a key phrase: first, fill the empty table with the letters of the key phrase (omitting spaces and duplicate letters), then fill the remaining spaces with the rest of the letters in alphabetical order. The key phrase is written in the top rows of the table, from left to right. For example, if the key phrase is "playfair example", the encryption key becomes:

To encrypt a message: - Remove all spaces, and split the message into digraphs (groups of letters), so for example, "Hello World" becomes "HE LL OW OR LD". - For each digraph, apply one of the following rules, using the key table:

Write a program that reads a key phrase and a plaintext to encrypt, and outputs the encrypted text.

The text to encrypt will not contain two consecutive characters or finish with an , to avoid indefinite application of the first rule.

Input

The input contains two lines. The first line contains the key phrase. The second line contains the text to encrypt. Each line will contain between and characters, inclusive. Each character will be a lowercase English letter, - (except ), or a space. No line will start or end with a space.

Output

Output a single line containing the encrypted text in uppercase, with no spaces.

Examples

Example 1

Loading
Loading