Guide
Rail fence and columnar transposition ciphers, step by step
Most classical ciphers replace letters with other letters. Transposition ciphers keep every letter exactly as it is and change the order instead. The two classic forms are the rail fence, which writes the message in a zigzag, and columnar transposition, which writes it in rows under a keyword and reads it by columns. This tool does both, and draws the zigzag or the grid so you can see what happened.
The rail fence cipher
Write the message diagonally down and up across a number of “rails”, like the rails of a fence. With three rails, WEAREDISCOVERED becomes W . . . E . . . on the top rail, E . R . D . S . on the middle and so on. Reading each rail from left to right gives the cipher text. The tool shows the zigzag with dots for empty positions. The classic example “We are discovered, flee at once” with three rails gives WECRLTEERDSOEEFEAOCAIVDEN.
Rails and offset
More rails scramble the order more. The offset starts the zigzag partway into its cycle, which changes the result without changing the rail count. Spaces are removed by default, as is traditional; keep them if you want them to move with the letters.
Columnar transposition
Write the message in rows under a keyword, one letter per column. Number the columns by the alphabetical order of the keyword’s letters, then read the columns down in that order. With the keyword ZEBRAS, the column under A is read first, then B, E, R, S and finally Z. The grid diagram shows the keyword, the column numbers and the rows.
Irregular or padded
If the last row is not full, the cipher is “irregular”: some columns are one letter shorter, which makes the cipher harder to break. Turn on padding to fill the last row with X so every column has the same length, as some textbooks do. Decryption works out the column lengths from the keyword and the message length, so both forms decrypt correctly — just use the same setting on both sides.
Decrypting and breaking
Decrypting with the right key reverses each step exactly. Without the key, transposition ciphers still have a weakness: the letters are the same as in normal English, so the frequencies of e, t, a and o look normal, which tells an analyst immediately that the cipher is a transposition. With few rails, simply trying each number breaks a rail fence in seconds.
Uses
Rail fence ciphers are a gentle introduction to cryptography for children. Columnar transposition appears in puzzle hunts and in the history of real military ciphers, including the double transposition used in both world wars.
A worked example
With three rails, HELLOWORLD is written in a zigzag: H, O and L on the top rail; E, L, W, R and D on the middle; L and O on the bottom. Reading the rails in order gives HOLELWRDLO. To decrypt, the tool rebuilds the same zigzag pattern, places the letters of HOLELWRDLO back on the rails and reads along the zigzag, giving HELLOWORLD again. The diagram under the result shows exactly this pattern with dots for the empty positions.
Related tools
Combine transposition with substitution using the Playfair Cipher, try the Caesar Cipher Solver or the Vigenère Cipher, or simply flip text with Reverse Text.
Checked against the current version of the Rail Fence & Columnar Transposition on .

