Advertisement

Rail Fence Cipher

A transposition cipher that writes the plaintext in a zigzag across N rails and reads ciphertext row by row.

Learn

A transposition cipher that writes the plaintext in a zigzag across N rails and reads ciphertext row by row.

In the rail fence cipher, the plaintext is written diagonally downward and upward across a number of 'rails' (rows), forming a zigzag pattern. Once the text is laid out, the ciphertext is read off row by row. The number of rails N is the key. The cipher is a pure transposition — no letter is changed, only rearranged — so letter frequencies in the ciphertext match the plaintext.

Write M diagonally on N rails (zigzag); read rail-by-rail to get C

  • HELLOWORLD, 3 rails → H...O...L | .E.L.W.R.D | ..L...O.. → HOLELWRDLO
  • 'WE ARE DISCOVERED' with 3 rails → zigzag then row-read
  • Decryption reverses the zigzag using the known number of rails

How to recognize it

  • The problem specifies a number of rails or rows
  • Ciphertext contains exactly the same letters as the plaintext (transposition)
  • Letter frequencies match the original language

Common mistakes

  • Mistaking it for a substitution cipher and analyzing frequencies
  • Reading the zigzag incorrectly (missing the 'up' portion of the bounce)
  • Using the wrong number of rails

Practice guidance

Coding & Decoding

Advertisement