IT lexicon › Security › Rail fence cipher

Rail fence cipher

Security På svenska → Updated: 2026-10-11

Write the plaintext in a zigzag across a few rows, then read it off row by row — a transposition cipher that yields to a pencil and five minutes of patience.

With three rails, the first letter goes on top, the second in the middle, the third at the bottom, the fourth back in the middle, and so on. The ciphertext is the top row, then the middle, then the bottom. No letter is substituted, only moved, so the letter frequencies match ordinary text exactly — a dead giveaway that you are looking at a transposition.

The entire key is the number of rails, and for a message of n characters there are fewer than n sensible choices. An attacker simply tries them all. These days it lives in puzzle books and classrooms, but the underlying idea — shuffle positions — survives as one half of every modern block cipher.

← Back to the lexicon