0% found this document useful (0 votes)
43 views

Rail Fence Cipher

The document describes implementing a Rail Fence cipher encryption algorithm in Python. The algorithm takes a plaintext string and encryption key as inputs and outputs the encrypted text. The program source code for the Rail Fence cipher encryption is provided.

Uploaded by

106Ashiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Rail Fence Cipher

The document describes implementing a Rail Fence cipher encryption algorithm in Python. The algorithm takes a plaintext string and encryption key as inputs and outputs the encrypted text. The program source code for the Rail Fence cipher encryption is provided.

Uploaded by

106Ashiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 8

RAIL FENCE CIPHER


AIM
Implement transposition cipher algorithm- Rail Fence Cipher

PROGRAM
# Rail fence implementation in python
def RailFence(text, key):
rail = [['\n' for i in range(len(text))] for j in range(key)]
down = False
row, col = 0,0

for i in range(len(text)):
if(row==0)or(row==key-1):
down = not down
rail[row][col] = text[i]
col += 1
if down:
row += 1
else:
row -= 1
encrypt = []
for i in range(key):
for j in range(len(text)):
if rail[i][j] != '\n':
encrypt.append(rail[i][j])
return("".join(encrypt))

def main():
print("-- Rail Fence Cipher (Encryption) --")
text = input("Enter the plain text: ")
key = int(input("Enter the key value: "))
print("Encrypted text: ", RailFence(text, key))

main()
OUTPUT

RESULT
Successfully implemented transposition cipher algorithm- Rail Fence Cipher.

You might also like