AMSCO1 - 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:

4 1 3 2 5
IN C OM P LE
T EC O LU M
NA R WI T HA
L TE R NA T
IN G SI N GL
E LE T TE R
SA N DD I GR
A PH S    

 

 

 

 

 

 

 

 

 

Input

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

Output

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

Example

Input:

41325 INCOMPLETECOLUMNARWITHALTERNATINGSINGLELETTERSANDDIGRAPHS Output:

 CECRTEGLENPHPLUTNANTEIOMOWIRSITDDSINTNALINESAALEMHATGLRGR

Added by:legrand
Date:2013-02-28
Time limit:0.108s-1s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 GAWK BASH C C++ 4.3.2 CPP C99 FORTRAN GO HASK JAVA OCAML PAS-GPC PAS-FPC PERL PIKE PYTHON PYTHON3 PY_NBC RUBY
Resource:classical ciphers

hide comments
2017-11-10 03:26:31
Problem statement is wrong - my solution got AC only when I changed it to ALWAYS start with a digraph when number of columns is even. This is mindboggling considering legrand himself actually insists it is otherwise.

12 ABCDEFGHIJKLMN -> ABDEGHJKMNCFIL

because:
1 2
AB C
DE F
GH I
JK L
MN

Other than that, enjoyed solving it.
2016-09-14 14:42:29 Bhumit
@legrand

Can you please check my submission?
ID - 17710888
Getting WA.
2016-03-27 06:10:46
Must For Beginners.......WA due to incorrect eof
2016-02-21 23:40:08
Nice problem :-) enjoyed it!
2015-02-20 21:05:15 :.Mohib.:
Easy One :)
2014-12-07 11:56:02 ROHIT RAJ
easy one...'\n'cost me 1 WA
2014-12-07 09:01:48 Nandu
very easy,
AC in 1st go
feeling Happy :D
2014-12-06 15:02:08 Diksha Jaiswal
AC :)

Last edit: 2014-12-08 11:00:20
2014-01-21 18:06:01 Bhavik
very nice implementation problem:)
2013-10-24 21:00:35 The_ROCK
don't know why i am getting WA...
submission id-10338955

AC.. just an initialisation problem.

Last edit: 2013-10-26 07:10:51
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.