Slanted Cipher Algorithm

A string is being encoded using a slanted transposition cipher that uses an integer numberOfRows. For example, assume the input string is ‘my name is’ and the number of rows is 3.The input string is encoded in a slanted fashion in 3 rows as given below. Gaps in the string are taken as blank characters.The output is then read row-wise, with the gaps being read as underscores.Hence, for the example given in the Capture1

the given encoded input string ‘mnes__ya_____mi’ reads as ‘my name is’ after decoding, which is the required output. Given the number of rows used and the encoded string, find the required output string.

6 Likes

Did you find the answer?

#1 read the input
[m, n, e, s,  ]
[ , y, a,  ,  ]
[ ,  ,  , m, i]
#2 shift i's row i to the left (circular array)
[m, n, e, s,  ]
[y, a,  ,  ,  ]
[ , m, i,  ,  ]

#3 read colums first and rows second. return the string you just read. done