EN
My tools

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.

Starts the zig-zag part-way through its cycle (0 = start on the top rail).
Ciphertext
WECRLTEERDSOEEFEAOCAIVDEN
Characters
25

The cycle repeats every 4 characters (down 2, up 2).

Zig-zag of the plaintext (read each rail left to right to get the ciphertext)
12345678910111213141516171819202122232425
Rail 1WECRLTE
Rail 2ERDSOEEFEAOC
Rail 3AIVDEN
My tools →
Advertisement

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

  1. Choose encode, decode, or decode without the key.
  2. Paste the text; tick the option to remove spaces and punctuation if your puzzle does.
  3. Set the number of rails and, if used, the offset.
  4. 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:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Rail Fence Cipher — Encode, Decode & Brute Force. https://kakao.mobile/tools/rail-fence-cipher-tool/

MLA

“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

Advertisement