프로그램 명: ncpc_playfair
제한시간: 1 초

The Playfair cipher is a manual symmetric encryption technique and was the first digraph substitution cipher. The scheme was invented in 1854 by Charles Wheatstone, but bears the name of Lord Playfair who promoted the use of the cipher.

The Playfair cipher uses a 5 by 5 table containing each letter in the English alphabet exactly once (except 'Q' which is missing). The table constitutes the encryption key. To more easily remember the table, it is typically generated from a key phrase. First ll in the spaces in an empty table with the letters of the key phrase (dropping spaces and duplicate letters), then fill the remaining spaces with the rest of the letters of the alphabet in order. The key phrase is written in the top rows of the table, from left to right.

For instance, if the key phrase is "playfair example", the encryption key becomes

P L A Y F
I R E X M
B C D G H
J K N O S
T U V W Z
To encrypt a message, one would remove all spaces and then break the message into digraphs (groups of 2 letters) such that, for example, "Hello World" becomes "HE LL OW OR LD". Then map them out on the key table, and apply the rule below that matches the letter combination: 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 'x's following each other, or an 'x' as the last character, as this might cause the first rule above to repeat itself indefinitely.

입력

The input contains two lines.

출력

The output should be a single line containing the encrypted text, in upper case. There should be no spaces in the output.

입출력 예

입력

playfair example
hide the gold in the tree stump

출력

BMNDZBXDKYBEJVDMUIXMMNUVIF

입력

the magic key
i love programming competition

출력

YDVHCWSPKNTAHKUBIPERMHGHDVRU
출처:ncpc/2009/Problem I

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]