The Black Chamber RU

Tools · Classical ciphers

Rail fence cipher

The rail fence: text zigzags across rails. See each letter land, and brute-force the rail count.

Runs in your browser. Your text goes nowhere.

How to use it

Type a text and choose the number of rails; the cipher text appears at once. To decrypt, switch to “Decrypt” or press “⇅”. Spaces are removed by default, so word lengths don’t give the text away; choose “keep” if you want them treated as ordinary characters.

The “fence” panel shows how it works. The letters of the plain text are laid out in a zigzag: down across the rails, then up, then down again. Each rail has its own colour. The cipher text is the rails read one after another: the whole top rail, then the second, down to the bottom one. The textbook example, WEAREDISCOVEREDFLEEATONCE on three rails, becomes WECRLTEERDSOEEFEAOCAIVDEN.

Start offset

The zigzag doesn’t have to start on the top rail. “Start offset” begins the text partway through the wave, as if the first few cells were skipped. It is a second, tiny piece of the key: with three rails there are only four offsets.

Brute force

The key of a rail fence is the number of rails, and the sensible choices are few: from two to about ten. So the “brute force” panel simply tries them all and ranks the results. Letter frequencies are no help here, because a transposition keeps every letter and only changes the order. The order, though, can be judged. Ordinary text is full of familiar pairs and triples like “th”, “er” and “ing”; a scrambled one has hardly any. The tool scores how much each candidate looks like language and puts the most plausible on top. “Rails and offsets” tries every offset too. Click a row and its key goes into the tool above.

Questions

Why “rail fence”?

The zigzag of letters looks like a fence of wooden rails. It is also called the zigzag cipher.

How is transposition different from substitution?

Substitution changes the letters; transposition only changes their order. A rail fence cipher text has the same letters, the same number of each, as the plain text. More in the lesson on transposition.

Is my text sent anywhere?

No, everything runs in your browser.