About the Cipher
The Rail Fence Cipher (also known as the zigzag cipher) is a form of transposition
cipher.
It gets its name from the way the message is written: up and down on successive "rails" of an imaginary
fence,
much like the wooden rails of a physical fence. Unlike the Playfair cipher which substitutes letters,
this cipher simply rearranges their order.
How It Works
- Define the Rails: Decide on a number of rows (rails) to use for the encryption.
- Write in Zigzag: Write the message starting at the top rail, moving down diagonally
until the bottom rail is hit, then moving back up diagonally.
- Encryption (Read Row by Row): To create the ciphertext, read the characters from
the grid starting from the top rail, then the second rail, and so on.
- Decryption (Fill the Path): Draw the zigzag path first using placeholders. Fill
these placeholders row-by-row with the ciphertext letters, then read the message following the
zigzag shape.