Hill encryption (devised by mathematician Lester S. Hill in 1929) is a technique that makes use of matrices and modular arithmetic. It is ideally used with an alphabet that has a prime number of characters, so we'll use the 37 character alphabet A, B, ..., Z, 0, 1, ..., 9,and the space character. The steps involved are the following:
Replace each character in the initial text (the plaintext) with the substitution . If the plaintext is ATTACK AT DAWN this becomes
Group these number into three-component vectors, padding with spaces at the end if necessary. After this step we have
After multiplying all the vectors by the encryption matrix, convert the resulting values back to the -character alphabet and concatenate the results to obtain the encrypted ciphertext. In our example the ciphertext is FPLSFA4SUK2W9K3.
This method can be generalized to work with any encryption matrix in which case the initial plaintext is broken up into vectors of length
. For this problem you will be given an encryption matrix and a plaintext and must compute the corresponding ciphertext.
Input begins with a line containing a positive integerindicating the size of the matrix and the vectors to use in the encryption. After this are
lines each containing
non-negative integers specifying the encryption matrix. After this is a single line containing the plaintext consisting only of characters in the
-character alphabet specified above.
Output the corresponding ciphertext on a single line.
The length of the strings <=100