Rail Fence Cipher — Encode, Decode & Brute Force
Encode and decode the rail fence (zig-zag) cipher with 2–20 rails and an offset, see the zig-zag grid, or brute-force every rail count ranked by English score.
The cycle repeats every 4 characters (down 2, up 2).
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Rail 1 | W | E | C | R | L | T | E | ||||||||||||||||||
| Rail 2 | E | R | D | S | O | E | E | F | E | A | O | C | |||||||||||||
| Rail 3 | A | I | V | D | E | N |
The rail fence cipher writes a message in a zig-zag across a number of "rails" and then reads each rail in turn. It is a transposition cipher: the letters stay the same and only their order changes, which is why frequency counts of the ciphertext look like ordinary English. This tool encodes and decodes with 2 to 20 rails and an optional offset, draws the zig-zag, and can break a message by trying every rail count.
How to use this tool
- Choose encode, decode, or decode without the key.
- Paste the text; tick the option to remove spaces and punctuation if your puzzle does.
- Set the number of rails and, if used, the offset.
- Copy the result, or read the ranked table in brute-force mode.
Formula
rail(i) = p if p < r, otherwise 2(r − 1) − p, where p = (i + offset) mod 2(r − 1)
i is the position of a character (from 0) and r the number of rails. Encoding writes rail 0, then rail 1 … then rail r − 1. Decoding counts how many characters fall on each rail, cuts the ciphertext into those pieces and reads them back along the zig-zag. Brute force scores every rail/offset pair by English letter-pair frequencies.
Example
With 3 rails, WEAREDISCOVEREDFLEEATONCE is written as W . . . E . . . C … on the top rail, E . R . D … in the middle and A . . . I … at the bottom, giving WECRLTEERDSOEEFEAOCAIVDEN. Decoding that string with 3 rails returns the original message.
Frequently asked questions
How do I decode a rail fence cipher without knowing the rails?
Use the third mode. It tries every rail count from 2 to 20 with every offset and ranks the results by how English the letter pairs look. Messages of a sentence or more usually come out on top.
Are spaces encrypted?
Here they are, like any other character, unless you tick "remove spaces and punctuation". Puzzle sites differ, so if a decode looks wrong, try the other setting.
What does the offset do?
It starts the zig-zag part-way through its cycle, as if some characters had already been written. With 3 rails the cycle has 4 positions, so the offset can be 0 to 3.
Is the rail fence cipher secure?
No. There are only a few hundred rail/offset combinations, so the brute-force mode above breaks it in a moment. Use it for puzzles and teaching, not to protect anything.
Last updated:
Page address with these inputs: https://kakao.mobile/tools/rail-fence-cipher-tool/
Cite or embed this tool
kakaoCalc. (2026, November 8). Rail Fence Cipher — Encode, Decode & Brute Force. https://kakao.mobile/tools/rail-fence-cipher-tool/
“Rail Fence Cipher — Encode, Decode & Brute Force.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/rail-fence-cipher-tool/.
Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms