CRYPTO4  The Bytelandian Cryptographer (Act IV)
The Bytelandian Cryptographer has been requested by the BBFO to put forward an encryption scheme which would allow the BBFO to communicate with its foreign associates. After some intensive studies, he has decided upon the Vigenďż˝re cipher. Messages written using 26 upper case characters of the Latin alphabet: A, B, ..., Z which are interpreted as integers 0,1, ..., 25 respectively. The secret cypher for transmitting a message is known to both sides and consists of n integers k_{1}, k_{2},...,k_{n}. Using this cypher, the ith number x_{i} of the input message x is encrypted to the form of the ith number of the output message y, as follows:
y_{i} =(x_{i}+k_{1+ ((i1) mod n)}) mod 26.
You are trying to find out the content of a message transmitted by the BBFO. By a lucky stroke of fortune, your spies managed to intercept the message in both its plaintext and encrypted form (x and y respectively). Unfortunately, during their dramatic escape the files they were carrying where pierced by bullets and fragments of messages x and y were inadvertently lost. Or were they? It is your task to reconstruct as much of message x as you possibly can.
Input
The first line of input contains a single integer t<=200 denoting the number of test cases. t test case descriptions follow.
For each test case, the first line contains one integer m which is some upper bound on the length of the cypher (1<=n<=m<=100000). The second line of input contains the original message x, while the third line contains the encrypted message y. The messages are expressed using characters 'A''Z' (interpreted as integers 025) and '*' (denoting a single character illegible due to damage). The total length of the input file is not more than 2MB.
Output
For each test case output a single line containing the original message x, with asterisks '*' in place of only those characters whose value cannot be determined.
Example
Input: 4 1 A*X*C **CM* 4 *B***A AAAAAA 6 *B***A AAAAAA 4 *AA******* AAAAAAAAAA Output: A*XHC *BA*BA *B***A *AA**A****Warning: large Input/Output data, be careful with certain languages.
The time limit is strict for this problem.
hide comments
robertosero:
20171031 16:25:19
how can K1 be any integer???? 

iamayushanand:
20160217 14:45:39
nice question Last edit: 20160220 14:53:53 

sidharth jain:
20140709 20:28:55
in the end got AC 

sidharth jain:
20140701 03:38:13
explain the last test case please! 

vincent Dass:
20130301 12:02:23
Super Problem....Very Easy ....


Ashutosh Singla:
20120602 19:52:07
i starts from 0 or 1 ?


Abhishek Joshi:
20120503 06:01:17
explain the first test case please?


Vladimir Tsibrov:
20111019 11:25:29
"then for #3 n=3 o/p should have been same"  thats right. but for n=6 output is *B***A. so what characters can be determined 100%? 

Darth Vadar:
20111018 16:29:01
Input #2 and #3 are same with max cypher length different, then how come the o/p are different? Means, if for #2 n=3 and the o/p is as given, then for #3 n=3 o/p should have been same, but why not? 

blashyrkh:
20110531 13:11:20
"The total length of the input file is not more than 2MB". Is it a maximum size of encrypted message, or is it a maximum size of input file with t<=200 test cases? 
Added by:  Konrad Piwakowski 
Date:  20041116 
Time limit:  17s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 VB.NET 
Resource:  DASM Programming League 2004 (problemset 3) 