Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
partial solution in Clear category for AMSCO Cipher by DiZ
def amsco(mode, message, key):
"""AMSCO cipher (mode = 1 to encode, -1 to decode)"""
n = row = ool = char = 0
grid, idx = {}, str(key)
# Put message characters in grid
while n < len(message):
grid[idx[ool], row, char], n, char = n, n + 1, char + 1
if char > (row + ool) % 2:
char, ool = 0, ool + 1
if ool == len(idx):
ool, row = 0, row + 1
# Compute translation table
table = dict((n, grid[k])[::mode] for n, k in enumerate(sorted(grid)))
# Assemble characters in right order
return ''.join(message[table[n]] for n in range(len(message)))
from functools import partial
encode_amsco, decode_amsco = partial(amsco, 1), partial(amsco, -1)
Sept. 26, 2014