Rail Fence Cipher Encoder & Decoder

Zig-zag transposition cipher with a choice of rails.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

The rail fence cipher is a classic transposition cipher dating to ancient times and popular in puzzles and intro-to-cryptography lessons. Your text is written in a zig-zag across a chosen number of rows, or rails, then read off one row at a time, so the letters are rearranged rather than substituted. Choose encrypt or decrypt, set the rail count, and type — output updates instantly in your browser.

How it works

To encrypt, the tool walks down and up the rails in a zig-zag. Starting on rail 0 moving down, each character is placed on the current rail; when it reaches the bottom rail it bounces back up, and when it reaches the top it bounces down. After all characters are placed, the rails are concatenated top to bottom to form the cipher text.

To decrypt, the same zig-zag path is reconstructed to count how many characters land on each rail. The cipher text is then sliced into those rail strings, and the original order is rebuilt by walking the zig-zag again and pulling the next character from the appropriate rail. Because the path is fully determined by the rail count, both sides must use the same number of rails or the result is gibberish.

Example

Encrypt WEAREDISCOVERED with 3 rails. The zig-zag layout is:

W . . . E . . . C . . . R . .
. E . R . D . S . O . E . E .
. . A . . . I . . . V . . . D

Reading each row left to right gives rail 1 = WECR, rail 2 = ERDSOEE, rail 3 = AIVD. Concatenated, the cipher text is WECRERDSOEEAIVD. Decrypting that same string with 3 rails restores WEAREDISCOVERED.

RailsEffect
2Splits text into odd and even positions
3Common classic setting (example above)
4+More rows, slightly more scrambling

Nothing you type is uploaded — the cipher runs entirely in your browser.

Ad placeholder (rectangle)