Rail Fence Cipher
The simplest transposition — a zigzag that fools no one twice
Why This Matters
The Rail Fence is one of the simplest transposition ciphers, yet it introduces the core concept that rearranging letter positions — without changing the letters themselves — can obscure a message. It has been used informally from antiquity through the American Civil War.
The Rail Fence cipher is one of the simplest transposition techniques, used informally for centuries before cryptographers took it seriously. The name comes from the appearance of the zigzag pattern resembling a split-rail fence. It was reportedly used during the American Civil War for simple field messages, though the Union Stager cipher was far superior.
Write the message diagonally across a set of 'rails', then read off each rail in sequence:
3 rails, HELLOWORLD: H . . . O . . . L . E . L . W . R . D . . L . . . O . . Read rows: HOL + ELWRD + LO = HOLELWRDLO
The key is simply the number of rails. With only a handful of possible values, any interceptor can try all possibilities in seconds.
The Rail Fence cipher has at most a dozen practical key values (number of rails). An attacker simply tries each rail count, decrypts, and checks if the result is English. The correct decryption is immediately obvious. Even a human can crack it in under a minute.
| Concept from Rail Fence Cipher | Modern Evolution |
|---|---|
| Positional rearrangement | AES ShiftRows: cyclic shift of row positions for diffusion |
| Read-by-row output | Bit permutation layers in DES and many stream ciphers |
| Tiny key space (few rails) | AES: 2¹²⁸ key possibilities — exhaustive search is computationally infeasible |
| Exhibit | 12 of 37 |
| Era | 19th Century |
| Security | Broken |
| Inventor | Unknown (folk cipher) |
| Year | ~1800s |
| Key Type | Number of rails (2-10) |
| Broken By | Brute force · Trivial keyspace |