Mathematical and Physical Journal
for High Schools
Issued by the MATFUND Foundation
Already signed up?
New to KöMaL?

Problem I. 385. (November 2015)

I. 385. The Playfair cipher (Source: \(\displaystyle {\rm https://en.wikipedia.org/wiki/Playfair\_cipher} \)) was invented by Charles Wheatstone in 1854, but he named it after his friend Lord Playfair who made the method popular. The encryption scheme itself had been broken before World War I, although Australians still used it in World War II (because computers were not yet available, and by the time that the enemy could break the message, the information would be useless to them).

The encryption scheme is based on a \(\displaystyle 5\times 5\) table containing the letters of the English alphabet-this alphabet has 26 letters, so we need to discard one letter, say, Q. The table is known only to the sender and the receiver.

The text to be encrypted (in our example FINOM IZ) is first partitioned into consecutive pairs of letters. If necessary, a new symbol (in our case X) is appended at the end. We proceed similarly if the original text contains a double letter in a pair: for example, AA is converted into AX AX.

During the encryption process, each pair of letters is replaced by another pair according to the following rules.

\(\displaystyle \bullet\) If both letters of the original pair are in a single row, then take the corresponding right neighbor in the table for each letter. The right neighbor of the last letter in a row is the first letter of the same row (FI \(\displaystyle \to\) RN).

\(\displaystyle \bullet\) If both letters of the original pair are in a single column, then take the corresponding lower neighbor in the table for each letter. The lower neighbor of the last letter in a column is the first letter of the same column (NO \(\displaystyle \to\) VN).

\(\displaystyle \bullet\) Finally, if the two letters of the original pair are found in different rows and columns, then we consider the rectangle whose diagonal is formed by these two letters. Letters of the new pair will be given by letters of the other diagonal of the rectangle, by keeping the same row for a letter (MI \(\displaystyle \to\) KF).

The first command-line argument of your program is either a character R or character V to denote whether the user wants to encrypt or decrypt data. The second argument is the input file name containing the Playfair table (read from left to right and top to bottom), the third argument is the input file name containing the text to be encrypted or decrypted, and the fourth argument is the output file name.

You can assume that the input text contains only uppercase letters of the English alphabet according to the above. Your program should be able to handle large (several GB in size) input or output files.

The source code and documentation of your program-containing a brief description of your solution, and the name of the developer environment to compile your code-should be submitted in a compressed file i385.zip.

Downloadable files (a possible Playfair table, and a sample original text file): kod.txt, be.txt.

(10 pont)

Deadline expired on December 10, 2015.


Statistics:

9 students sent a solution.
10 points:Nagy Ábel, Olexó Gergely.
8 points:3 students.
7 points:1 student.
6 points:2 students.
4 points:1 student.

Problems in Information Technology of KöMaL, November 2015