RAILFENCE ENCRYPTION - PE
def rail_fence_encrypt(message, num_rails):
# Initialize a list for each rail
rails = ['' for _ in range(num_rails)]
index, step = 0, 1
for char in message:
rails[index] += char
if index == 0:
step = 1
elif index == num_rails - 1:
step = -1
index += step
#Join all the rails to get the encrypted message
return ''.join(rails)
def main():
print("=== Rail Fence Cipher Encryption ===")
message = input("Enter the message to encrypt: ")
num_rails = int(input("Enter the number of rails: "))
encrypted = rail_fence_encrypt(message, num_rails)
print("\n--- Output ---")
print("Input:", message)
print("Encrypted (Rail Fence):", encrypted)
if name == "main":
main()