Answers for "rail fence cipher in python"

0

python rail fence cipher

# Rail-Fence Transposition Cipher
def rail_fence_encrypt():
    word = list(input("Enter the plain text: "))
    even, odd  = [word[i] for i in range(0, len(word), 2)], [word[i] for i in range(1, len(word), 2)]
    return ''.join(even) + ''.join(odd)

def rail_fence_decrypt():
    word = list(input("Enter the plain text: "))
    if(len(word) % 2 == 0):
        odd, even = word[: int(len(word) / 2)], word[int(len(word) / 2): ]
    else:
        odd, even = word[: int(len(word) / 2) + 1], word[int(len(word) / 2) + 1:]
    if (len(odd) != len(even)):
        even.append(' ')
    plain = [odd[i] + even[i] for i in range(len(odd))]
    return ''.join(plain)
Posted by: Guest on November-24-2020

Python Answers by Framework

Browse Popular Code Answers by Language