AMSCO2 - Decipher the AMSCO cipher

no tags 

Here you have to decipher the AMSCO cipher:

Due to A.M.SCOtt in the 19th century, it's an incomplete columnar transposition cipher with alternating single letters and digraphs. The first entry must be a digraph. In both even and odd periods the first column and the first row always alternate:

7 4 5 6 3 2 1
RI D ER S ON T HE
S TO R MI N TO T
HI S HO U SE W EA
R EB O RN J IM M
OR R IS O N

Input

N lines (N < 1000) Each line of the input contains the numeric key (permutation order of the columns) and a ciphertext. Ciphertext letters are in [A-Z] only with no punctuation. The keylength max is 9 and the length of the ciphertext is limited to 250. The last line ends with EOF.

Output

Output consist of exactly N lines of plaintexts with letters in [A-Z] with no spaces.

Example

Input:
7456321 HETEAMTTOWIMONNSEJNDTOSEBRERRHOOISSMIURNORISHIROR

Output:
RIDERSONTHESTORMINTOTHISHOUSEWEAREBORNJIMMORRISON
Input:
41325 CECRTEGLENPHPLUTNANTEIOMOWIRSITDDSINTNALINESAALEMHATGLRGR

Output:
INCOMPLETECOLUMNARWITHALTERNATINGSINGLELETTERSANDDIGRAPHS

hide comments
nadstratosfer: 2017-11-10 04:55:00

Reused AMSCO1 code in a really dumb way. Not too proud of this AC..
Edit: Having failed to debug an optimized solution, I concede that the dumb way was the correct approach ;)

Last edit: 2017-11-10 07:33:43
blazekid_dtu: 2016-03-31 20:52:45

doing AMSCO1 before this makes it a cakewalk.

Daksh: 2015-12-28 16:18:41

just add 10 lines in AMSCO1 :D :)

ROHIT RAJ: 2014-12-07 10:26:32

finally AC... feels great

Diksha Jaiswal: 2014-12-03 18:40:12

1 WA cos of differences in compilers like ideone n d one used for judging in spoj...feels grt to see green light :D

Jumpy: 2014-03-28 08:46:21

nice problem damn happy now

Saurabh Jain: 2013-06-30 19:13:50

@legrand: I am getting WA again n again even though I verified my solution with a lot of test cases generated using amsco1 code. Can you please give me a hint for the occurrence of same?
=> 30% wrong testcases
@legrand: Thanks .. Got AC :)

Last edit: 2013-07-08 06:55:51
Utsav Sinha: 2013-06-10 18:54:57

@legrand: please check my code, id - 9455124, it works for the test cases and many cases produced from AMSCO1, but gives wrong answer. thanks in advance...
=>verify the length of your answers: at the end of all your wrong outputs there are 2 or 3 '\0' and sometimes an extra alpha char before the '\n'

@legrand: Thanks !! AC :)

Last edit: 2013-06-12 15:27:15
vishal chaudhary: 2013-06-06 20:21:57

@legrand: plz check my code, its working fine but i m getting WA, code id: 9393145 ,thank you..
=>your code fails for a lot of testcases. you can debug it by more testcases generated with your amsco code.

i've tested many cases generated with my amsco code..works fine every time...don't know where it is wrong :'(
=>test with more testcases ending with an extra char like in the exemple 'riders on the strom'

Last edit: 2013-06-12 12:30:38
legrand: 2013-06-06 20:21:57

no, the ciphertext's length is at least three times the key's length.


Added by:legrand
Date:2013-04-04
Time limit:0.100s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 GAWK BASH C C++ 4.3.2 CPP C99 LISP sbcl LISP clisp FORTRAN GO HASK JAVA LUA OCAML PAS-GPC PAS-FPC PERL PHP PIKE PYTHON PYTHON3 PY_NBC RUBY SCM guile SCM qobi
Resource:classical ciphers