ZOJ Problem Set - 2768
Jim is a young boy, he has learnt a lot of knowledge of mathematics. He does not want others to know his secrets so he encrypts his text using one simple method. Let us assume that p0, p1, p2, p3, p4 are 5 characters which Jim wants to encrypt. He randomly chooses 9 numbers k0...k8 to be his cipher keys. These 9 cipher keys are between 1 and 127. e0, e1, e2, e3, e4 are 5 characters which have been encrypted.
Below is the encrypt method he uses:
But his father wants to know what Jim has written. He has some proclaimed in writing (this means text which has not been encrypted) and its corresponding encrypted text. His father wants you to decipher other encrypted texts.
An integer N in the first line is the number of test cases. N test cases follow.
In each test case, the first line is proclaimed in writing whose length is at least 10. The second line is the encrypted text which corresponds to the first 5 characters on the first line. The third line is the encrypted text which corresponds to the 6-10 characters on the first line. The fourth line is an integer indicating the number of lines followed in this test case. From the fifth line, every line followed contains five integers which correspond to 5 encrypted characters.
Print the text which you have deciphered.
1 John Q. Crackjack 30096 28880 32662 34217 36518 22426 23187 28934 27877 29942 4 34391 35683 39956 40657 45237 33044 30700 34923 37133 38330 37200 37645 43055 43698 47491 32574 30389 35225 36978 38050
Author: GAO, Junxin
Source: ZOJ Monthly, October 2006