Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for AMSCO Cipher by Tinus_Trotyl
def pull(s): # if possible pull 1st char from string
if s: return s[0], s[1:]
else: return "", ""
def pull2(s): # if possible pull 1st 2 (or 1) char from string
a, s = pull(s)
b, s = pull(s)
return a + b, s
def decode_amsco(message, key):
key = [int(i) - 1 for i in str(key)] # transform key to a more suitable form
grid, msg, row = [], message, -1
while msg: # set up a grid
row += 1
grid = grid + [[[0,""] for i in key]]
for x in range(len(key)):
if (row + x) % 2 == 0: c, msg = pull(msg)
else: c, msg = pull2(msg)
grid[row][x][0] = len(c)
for x in range(len(key)): # fill in
i = key.index(x)
for row in range(len(grid)):
n = grid[row][i][0]
if n == 1: grid[row][i][1], message = pull(message)
if n == 2: grid[row][i][1], message = pull2(message)
return "".join(x[1] for row in grid for x in row) # and read out
June 22, 2017
Comments: