Deciphering Messages |
For each plaintext message the initial value for m is one.
The function ciph translates each letter to the letter N letters after it in the alphabet and arithmetic is performed as if the alphabet were circular (for example, if N is 2, then ciph(A) = C, ciph(B) = D,..., ciph(X) = Z;ciph(Y) = A;ciph(Z) = B).
NOTE: The keys used in the processes of ciphering and deciphering
are such that the ciphered text can always be
uniquely deciphered (that is, the keys do not contain images of
function ciph for none of its elements).
Your task is to write a program to decode messages encripted by
using the method just described.
Input data file contains the alphabetical key in the first line, the numerical key in the second line, the number of messages that are to be deciphered in the third line, and a ciphered text message in each of the remaining lines. These text messages only contain uppercase letters in the standard 26-letter English alphabet and, if it is the case, also a space between words. These text messages supposedly result from the encryption of several original plaintext messages using the method described above with the cipher key given in the first and second lines of the input file.
For each of the input ciphered text messages, output of the original
plaintext message is required or an error message
(`error in encryption') in case the input text is not a correct
encryption of any plaintext message. The order
of the messages must be preserved.
1 RSAEIO 2 5 RTSSKAEAGE GRSCAV RGSSCAV RUSIQO RUSSGAACEV JEGIITOOGR
RICE error in encryption EAT error in encryption SEAT HERE