Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
49 - ZOJ Monthly, December 2005 - 1007
Transposition Cipher

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Encrption mathods have historically been divided into two categories:substitution ciphers and tranposition ciphers.Transposition ciphers recorder the letters but do not disguise them.There is a common transposition cipher,the columnar transposition.The cipher is keyed by a word or phrase not containing any repeated letters.For example:

M E G A B U C K
7 4 5 1 2 8 3 6
p l e a s e t r
a n s f e r o n
e m i l l i o n
d o l l a r s t
o m y s w i s s
b a n k a c c o
u n t s i x t w
o t w o

Plaintext

pleasetransferonemilliondollarstomyswissbankaccountsixtwotwo

Ciphertext

AFLLSKSOSELAWAITOOSSCTLNMOMANTESILYNTWRNNTSOWPAEDOBUOERIRICX

MEGABUCK is the key.The purpose of the key is to number the columns, column 1 being under the key letter closest to the start of the alphabet,and so on.The plaintext is written horizontally,in rows.The ciphertext is read out by columns,starting with the column whose key letter is the lowest.

Input:

The input file contains several testcases. The first line is the positive integer number n of the test cases. Then n test cases following. Each test case is composed of the following information:
The first line is the key with uppercase letters.The length of the key is m(1<=m<=26).Then is the ciphertext with uppercase letters and one per line. The length of the ciphertext is not more than 100.

Output:

For each test case,print the plaintext computed from the ciphertext.One per line.

Sample Input:
1
MEGABUCK
AFLLSKSOSELAWAITOOSSCTLNMOMANTESILYNTWRNNTSOWPAEDOBUOERIRICX
Sample Output:
pleasetransferonemilliondollarstomyswissbankaccountsixtwotwo

Author: JIANG, Yongli


Submit    Status