Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for AMSCO Cipher by kurosawa4434
def decode_amsco(message, key):
key_len = len(str(key))
msg_len = len(message)
word_len = 1
keys = [[] for _ in range(key_len)]
i = 0
# make matrix of key
while msg_len > 0:
keys[i].append(word_len if msg_len > 1 else 1)
msg_len -= word_len
if not (key_len % 2 == 0 and i + 1 == key_len):
word_len = 3 - word_len
i = i + 1 if i < key_len - 1 else 0
# map character
for i in range(key_len):
idx = str(key).find(str(i + 1))
for j, n in enumerate(keys[idx]):
keys[idx][j] = message[:n]
message = message[n:]
# make result
result = ''
for i in range(len(keys[0])):
for j in range(key_len):
if len(keys[j]) - 1 >= i:
result += keys[j][i]
return result
July 25, 2016