Secret codes

The rail fence cipher

Date: c. 1860

Letters written in waves over several rows, then read row by row

Transposition ciphers
ATTACKATDAWNACDTAKTANTAW
Illustration drawn for the site

In brief

In the rail fence cipher, the message is written going down then up over several rows, like a zigzag fence. Each row is then read one after the other. It is a simple transposition, very popular in games.

The story

With two rows, you write one letter at the top, the next at the bottom, then top, then bottom… and copy out the top row first, then the bottom one. With three rows or more, the letters go down and up in a wave. The number of rows is the key. This cipher is said to have been used in the American Civil War, in the 1860s, for quickly written field messages.

Like the scytale, it replaces no letters: a rail fence message contains exactly the same letters as the original text, out of order. A codebreaker soon notices this by counting the letters, then tests different numbers of rows. It remains ideal for learning how transposition works.

Example

3 rows: ATTACKATDAWN → ACDTAKTANTAW

Try it in the workshop

Did you know?

To decrypt, draw the empty wave with the right number of boxes, then fill each row with the letters of the message, in order.

Sources: D. Kahn, The Codebreakers, 1967 (rev. ed. 1996); S. Singh, The Code Book, 1999; F. L. Bauer, Decrypted Secrets, 4th ed., 2007; C. P. Bauer, Secret History: The Story of Cryptology, 2nd ed., 2021; texts written for this site.

In the same family: Transposition ciphers