Skip to main content

Rail Fence Cipher

AKA: ZigZag/WigWag Cipher

The Rail Fence Cipher is a transposition cipher that rearranges the letters of a message to create a new encrypted message. It gets its name from the way the letters are written in a zigzag pattern that resembles a fence made of rails.

Here's how the Rail Fence Cipher works:

  1. You start by writing the message in a zigzag pattern, with each row representing a "rail" of the fence.

  2. The message is written diagonally, moving up and down the rails until reaching the end of the fence.

  3. Once the zigzag pattern is completed, you read off the letters row by row to create the encrypted message.

For example, let's encrypt the message "HELLO WORLD" using a Rail Fence Cipher with three rails:

H . . . O . . . L . .
. E . L . W . R . D .
. . L . . . O . . . !

The encrypted message is "HOL ELWRD LO!".

To decrypt the message, you follow the same process. Write the encrypted message in the zigzag pattern, filling in the rails row by row, and then read off the letters in the original order.

The Rail Fence Cipher is a relatively simple transposition cipher and can be easily decrypted with the knowledge of the number of rails used. It provides a basic level of security but is generally considered a weak encryption method and is susceptible to various cryptanalysis techniques.

Please note that the Rail Fence Cipher is just one of many historical ciphers and is not commonly used in modern cryptographic applications.