python rail fence cipher

Solutions on MaxInterview for python rail fence cipher by the best coders in the world

showing results for - "python rail fence cipher"
Jackson
12 Aug 2016
1# Rail-Fence Transposition Cipher
2def rail_fence_encrypt():
3    word = list(input("Enter the plain text: "))
4    even, odd  = [word[i] for i in range(0, len(word), 2)], [word[i] for i in range(1, len(word), 2)]
5    return ''.join(even) + ''.join(odd)
6
7def rail_fence_decrypt():
8    word = list(input("Enter the plain text: "))
9    if(len(word) % 2 == 0):
10        odd, even = word[: int(len(word) / 2)], word[int(len(word) / 2): ]
11    else:
12        odd, even = word[: int(len(word) / 2) + 1], word[int(len(word) / 2) + 1:]
13    if (len(odd) != len(even)):
14        even.append(' ')
15    plain = [odd[i] + even[i] for i in range(len(odd))]
16    return ''.join(plain)