Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
iter solution in Clear category for AMSCO Cipher by blabaster
from itertools import chain, cycle
def amsco(iterable, key):
matrix, it, odd_row = [[_] for _ in str(key)], iter(iterable), 1
try:
for l in cycle(chain([None], matrix)):
if l is None:
one_two = odd_row = 3 - odd_row
else:
one_two = 3 - one_two
for _ in range(one_two):
l.append(next(it))
except StopIteration:
return chain(*[_[1:] for _ in sorted(matrix)])
def encode_amsco(message, key):
return ''.join(amsco(message, key))
def decode_amsco(message, key):
return ''.join((_[1] for _ in sorted(zip(amsco(range(len(message)), key), message))))
Sept. 18, 2014
Comments: