Rail Fence Cipher

Photo by Randy Fath on Unsplash

Rail Fence Cipher

·

1 min read

The rail fence cipher (also called a zigzag cipher) is a classical type of transposition cipher. It derives its name from how encryption is performed, in analogy to a fence built with horizontal rails. Rails can be anywhere from two to more rails.

Encryption

Message: This is a secret message.

Rail: 2

Output: TIIAERTESG HSSSCMSAE

Decryption

Note: Knowing the number of "Rails" and the message length is enough for decryption.

Input: TIIAERTESG HSSSCMSAE

Rail: 2

Message Length: 20

Output: This is a secret message.