Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
AMSCO cipher solution in Clear category for AMSCO Cipher by przemyslaw.daniel
def codec_amsco(msg_len, key):
from functools import reduce
msg, key_len, pos = list(range(msg_len)), len(str(key)), 0
data = [[[]]*key_len for _ in range(msg_len//key_len+1)]
while msg:
x, y = pos // key_len, pos % key_len
data[x][y] = msg[:1+(x+y) % 2]
msg, pos = msg[1+(x+y) % 2:], pos + 1
data = [reduce(lambda i, j: i+j, x) for x in zip(*data)]
key = [i for _, i in sorted([[x, i] for i, x in enumerate(str(key))])]
return reduce(lambda i, j: i+j, [data[x] for x in key])
def encode_amsco(message, key): # example implementation of encoder
return ''.join([message[x] for x in codec_amsco(len(message), key)])
def decode_amsco(message, key):
c = codec_amsco(len(message), key)
return ''.join([message[c.index(x)] for x in range(len(message))])
Jan. 1, 2017