if 0:
    for rail in fence:
        print(''.join('.' if c is None else str(c) for c in rail))
return [c for rail in fence for c in rail if c is not None]

def encode(text, n):
    return ''.join(fence(text, n))

def decode(text, n):
    rng = list(range(len(text)))
pos = fence(rng, n)
return ''.join(text[pos.index(n)] for n in rng)
z = encode('ATTACK.AT.DAWN', 3)
print(z)
y = decode(z, 3)
print(y)
Rail Fence Cipher — в поисках лучшего решения