I. 204. As we have seen in Problem I. 201. in our last Issue, the Cardan grille can be used to encode messages. Write a program that encodes a given text using a given grille, that is, produces a suitable arrangement of letters of the text according to the grille.
The structure of the grille in its initial position is read from a text file being the first command line argument of your program. If the size of the grille is N×N, then this file has N lines: each line consists of ``o'' or ``.'' characters. The ``o'' symbol represents a ``hole'': letters under these squares are visible. The original text is read from a text file specified by the second command line argument. This file (having one or more lines) can contain lowercase and uppercase letters of the Hungarian alphabet, further space characters and the usual punctuation marks. The output of your program should be a text file given in the third command line argument. This file should contain blocks of N×N letters, separated by empty lines.
Encoding starts from the beginning of the text, and successively creates blocks of N×N letters. These blocks can contain letters only from the original text, but converted into uppercase characters. Spaces, newline characters and other punctuation marks should not be included. Note that the encrypted text could be decoded easily if the last block of letters is incomplete (due to the fact that the original text has ended). To avoid this problem, you should copy the appropriate number of letters from the beginning of the text and attach these to the end of the text so that the last block of letters becomes complete.
In the example, ``Első fájl (a rács)'' means ``First file (grille)'', ``Második fájl (a szöveg)'' means ``Second file (original text)'', while ``Harmadik fájl (a titkos)'' is ``Third file (encoded)''.
The source code of your program (i204.pas, i204.cpp, ...) together with a short documentation (i204.txt, i204.pdf, ...) should be submitted, also containing a brief description of your solution and the name of the developer environment to use for compiling.
Deadline expired on 16 February 2009.
Google Translation (Sorry, the solution is published in Hungarian only.)
A feladat megoldása az alábbi FreePascal környezetben készült, érthetően kommentezett programból nyomon követhető (i204.pas).
A megoldásokat a mellékelt tömörített állományban található bemenetekkel teszteltük, emellett a kapott a kimeneteket is közreadjuk. (teszt.zip).