What it is
The Rail Fence is a transposition cipher: it keeps every letter but scrambles their order. You write the message in a zigzag down and up across a number of "rails" (rows), then read each rail from left to right. The key is the number of rails. Shuffling letters this way is very old: Spartan generals did it by winding a strip around a staff. Read about that on the Archive card The Spartan Staff.
Draw the zigzag
Lay example 2 out on 2 to 5 rails. The right number turns it back into words along the zigzag.
Pick a number of rails.
How to encode
- Drop the spaces and write the letters in a zigzag: down one rail per letter to the bottom, then back up.
- Read the top rail left to right, then the next rail, and so on.
MEET BY THE CANAL on 2 rails:
Reading the rails gives MEBTEAA + ETYHCNL = MEBTEAAETYHCNL.
How to break it, step by step
- Suspect it when the letters look like normal English (plenty of E, T, A) but in the wrong order. That's a transposition, not a substitution.
- Count the letters. The zigzag repeats every 2 × (rails − 1) letters, so the top rail gets about one letter in every cycle.
- Try 2 rails, then 3, then 4. For each, split the cipher text into rails of the right lengths, lay them on the zigzag and read along it.
- Stop when it reads as words. Then put the spaces back by sense.
Worked example 1: rails given
2 rails. Decode MEBTEAAETYHCNL.
With 2 rails, the first 7 letters are the top rail and the rest are the bottom. Lay them alternately: top, bottom, top, bottom… That gives MEETBYTHECANAL, or with spaces, MEET BY THE CANAL.
Worked example 2: rails unknown
PTLRSAKHBUCAECEET
| Rails | Read along the zigzag |
|---|---|
| 2 | PUTCLARESCAEKEHTB |
| 3 | PACKTHEBLUECRATES |
| 4 | PRBEUSTACEAKLHETC |
Three rails gives English: PACK THE BLUE CRATES.
Common mistakes
- Splitting the rails into equal lengths. The top and bottom rails are shorter than the middle ones.
- Reading down the columns instead of along the zigzag.
- Expecting word breaks to survive: they don't, so add them back by sense.