Rail Fence Encryption and Decryption in Python

Опубликовано: 27 Сентябрь 2024
на канале: VoxelPixel
4,283
31

Rail Fence Cipher in Python
00:47 - Encryption
02:17 - Testing Matrix
02:50 - Putting letters one by one in matrix in zig-zag
04:14 - testing zig-zag matrix
04:47 - changing zig-zag matrix to encrypted string, row by row
06:03 - testing encryption
06:13 - Decryption
07:50 - changing order of cipher text letters in matrix, to make it possible to be decrypted
08:57 - testing cipher reordering
09:46 - adding re ordered text in to decrypted string, diagonally to get un-encrypted text
11:47 - Decryption Testing

-*- Support on Patreon:   / voxelpixel  
-*- Source Code: https://github.com/VoxelPixel

rail fence cipher encryption and decryption using python programming language

Rail fence is sometimes also called a zig zag cipher.
Rail fence cipher is a transposition cipher, its algorithm is as following:

-- To Encrypt --
Take a plain text message.
Define number of rows.
Start writing plain text message, letter by letter in rows in zig-zag ordering.
Once all letters are written in zig zag, write all the letters of first row.
Followed by all letters of the second row, continue doing this until all rows are covered.
This new written collection of letters is cipher text.

-- To Decrypt --
Take cipher text.
Define number of rows.
Count total number of letters in ciphertext.
now start putting any random symbol lets suppose a '.' in zig-zag, in rows and keep doing that till number of '.' is

equal to number of letters in cipher text.
Now start putting letters of cipher text at places of '.' but this time don't put in zig-zag, instead, this time put

letters one by one as they are in cipher text on dots in rows
Once all rows are covered, take letters one by one in zig-zag from newly created zig-zag matrix after replacing '.'

with letters
This new line is decrypted plain text.