UTILS.
100% in-browser
🚂

Rail Fence Cipher Encoder / Decoder

Zig-zag transposition cipher: write text diagonally across N rails then read it off row by row. Encode or decode with adjustable rails and starting offset.

— output appears here —

About this tool

The Rail Fence Cipher Encoder / Decoder is a free, in-browser tool for the best-known transposition cipher. Instead of substituting letters it rearranges them: the plaintext is written in a zig-zag down and up across a chosen number of horizontal rails, then read off one full rail at a time from top to bottom. With 3 rails the letter positions follow the pattern 0,1,2,1,0,1,2,… so consecutive characters land on different rows before being regrouped.

To decode, the tool rebuilds the exact zig-zag path for the ciphertext length, works out how many characters belong to each rail, slices the ciphertext into those rails, and then walks the zig-zag again to lift the letters back into their original order. It supports 2 or more rails, an optional starting offset that shifts where in the zig-zag the first letter sits, and treats a single rail as an identity (no change). Everything runs locally in your browser with nothing uploaded.

By default spaces and punctuation are carried along as ordinary characters so the transposition is fully reversible; a toggle lets you strip non-letters before encoding when you want a clean letters-only ciphertext. The rail fence is the classic partner to the Caesar cipher in cryptography lessons and a frequent sight in CTF challenges and escape rooms, illustrating how transposition ciphers hide a message by scrambling position rather than identity.

Frequently asked questions

How does the rail fence cipher work?
Characters are written diagonally across N rails in a zig-zag — down to the bottom rail, back up to the top, and so on — then read off rail by rail from top to bottom. It is a transposition cipher: it reorders letters instead of substituting them.
How does decoding recover the text?
The tool recreates the zig-zag pattern for the ciphertext length to count how many letters each rail holds, cuts the ciphertext into those rails, then follows the zig-zag path again to read the letters back in their original order.
What does the offset do?
The offset shifts where in the zig-zag cycle the first character starts, effectively beginning partway down a rail. The same offset must be used for encoding and decoding to get a matching result.
Why keep spaces and punctuation?
Keeping every character makes the transposition exactly reversible, so decoding returns your original text including spacing. Use the strip option to remove non-letters first when you want a compact, letters-only ciphertext.

More tools