Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for AMSCO Cipher by mortonfox
def decode_amsco(message, key):
key_str = str(key)
key_len = len(key_str)
# Set up the matrix.
remain_chars = len(message)
matrix = []
row = 0
while remain_chars > 0:
this_row = []
for col in range(key_len):
nchars = min(remain_chars, 1 if (row + col) % 2 == 0 else 2)
this_row.append(nchars)
remain_chars -= nchars
matrix.append(this_row)
row += 1
# Fill the matrix.
for i in range(1, key_len + 1):
col = key_str.find(str(i))
for row in matrix:
nchars = row[col]
row[col] = message[:nchars]
message = message[nchars:]
return ''.join([''.join(row) for row in matrix])
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert decode_amsco("oruoreemdstmioitlpslam", 4123) == "loremipsumdolorsitamet", "Lorem Ipsum"
assert decode_amsco('kicheco', 23415) == "checkio", "Checkio"
assert decode_amsco('hrewhoorrowyilmmmoaouletow', 123) == "howareyouwillhometommorrow", "How are you"
Dec. 16, 2016