Output: Standard Output
The Playfair cipher was invented more than
one and a half century ago by Sir Charles Wheatsone, one of the pioneers of the
electric telegraph. It was made popular by Baron Playfair
of
To encrypt a message, the text is first
converted to groups of two capitals, called digraphs. This is done as follows:
Consider the
following message: "Programming in C and Pascal is easy; I will learn Java
next year." The digraph representation would be:
PR OG RA MX MI NG IN CA ND PA SC
Note the
extra 'X' between the two 'M's of 'programming'. There is no extra 'X' between
the two 'L's of 'will', because they are in different digraphs, but there is
one between 'will' and 'learn'. There is also an extra 'X' at the end of the
message. The 'J' in 'Java' is replaced by an 'I'.
To illustrate the exceptions for the letter 'X' in the original text, consider
the message "I am an ex-xenophobe, attempting to relax!".
This becomes:
IA MA NE XQ XE NO PH
The next stage is the replacement of each
digraph by an other digraph according to the following
rules:
The
resulting digraphs form the encrypted code.
Consider the key:

The first digraph of the first example
above is 'PR'. Since the letters are not in the same row or column, 'P' is
replaced by 'F' and 'R' is replaced by 'V'. The replacement digraph is 'FV'.
Similarly the following digraphs, 'OG',
'RA', 'MX','MI', 'NG' and 'IN', are replaced by resp.
'CV', 'GE', 'PH', 'PW', 'AS' and 'UX'.
In the next digraph, 'CA', the letters
occur in the same column, so 'C' is replaced by 'G' and 'A' is replaced by 'L',
resulting in the new digraph 'GL'.
We also encounter the digraph 'EA' with
letters in the same row. It's converted to 'HE'. Horizontal wrap around is
encountered during the conversion of 'IW', 'IL' and 'EX'. No vertical wrap
around occurs in the example, but the digraph 'BM' would convert to 'HK'.
The complete encryption of the first
message is:
FV CV GE PH PW AS UX GL UY ZX GY LZ UV HE NS UI UQ IA QA EG
XU XG EA HN KC HE VE
The second
message encrypts to:
LX ZH AH EI NH XY MX KV HE OE RQ PD OQ AS KY EQ ZL EI
Decryption is easy once you know the key.
That process is not described here, because I trust you can figure that out for
yourself.
In this problem you will implement a so called 'known plaintext attack'. You have a piece of plain text and you also have it's encrypted code. From that information you will have to deduce a key and use that key to decode another piece of encrypted text.
Input
For each case, first output a line "Case x:"
where x is the case number (starting from 1).
Then output the decrypted code represented as digraphs in the same format as the
code parts in the input. Separate the cases by an empty line.
It is guaranteed that the first two parts of each case contain enough
information to uniquely decode any possible encoded text.
|
2 Programming in C and Pascal is easy; I
will learn Java next year. # FV CV GE PH PW AS UX GL UY ZX GY LZ UV HE
NS UI UQ IA QA EG XU XG EA HN KC HE VE # LX ZH AH EI NH XY MX KV HE OE RQ PD OQ AS
KY EQ ZL EI # It is full moon! Meet me at # MP PI NZ AZ RN QV UG GD DO GD RQ AR KY GD
HD NK PR DA MS OG UP GK IC QY # HL WT UP MC HQ RW PI CX DC ZD HB HG KL PM
GI FP SK GE QR MF MP AR BH HM HA SP DP TC WM DZ UH GI RZ CD EV KY GD MF IP GT IF KG IC EH TE
SD QV QG PR RQ EV MU EV FS DA BC MK GI # |
Output for Sample Input
|
Case 1: IA MA NE XQ XE NO PH Case 2: CR YP TO GR AP HY IS AV ER YF AS CI NA TI
NG SU BI EC TA ND IT HA SA RI CH HI ST OR YI FY OU AR EI NT
ER ES TE DI NT HE PL AY FA IR CI PH ER SA ND MA NY MO RE OT
HE RS IC AN ST RO NG LY RE CO MX ME ND SI MO NS IN GH SC OD
EB OX OK TH AT CO NT AI NS CO DE BR EA KI NG |
Problemsetter: Joachim
Wulff (aka Little Joey)
Special Thanks: Derek Kisman, EPS
The plaintext for the second example is:
Cryptography is a very fascinating subject
and it has a rich history. If you are interested in the Playfair
ciphers and many more others, I can strongly recommend Simon Singhs "Code Book" that contains all about the
secret history of codes and code breaking.
The key was taken from Appendix E that contains the explanation of the Playfair cipher.
I owe my fascination for cryptography to Simon Singh.