Skip to content
TextArray
100% local

Rail fence cipher

Encrypt and decrypt the classic zigzag transposition with a configurable rail count.

Input
Output

Rail fence cipher

The rail fence is the transposition cipher everyone meets first: write the message diagonally, bouncing between the top and bottom of an imaginary fence, then read it off row by row. WE ARE DISCOVERED FLEE AT ONCE on three rails becomes WECRLTEERDSOEEFEAOCAIVDEN — every letter is still there, only the order changed. This tool runs it both ways: encrypt scrambles, decrypt rebuilds the zigzag and reads the message back out.

The rail count is the key — two rails barely shuffle, twenty rails on a short message change nothing at all (the zigzag never folds), and the sweet spot in classic puzzles is three to five. The offset option starts the zigzag partway through its cycle, a common variant in geocaching and CTF challenges that breaks naive solvers. By default whitespace is stripped before ciphering, the classical presentation; keep spaces and punctuation switches to a pure transposition of every character, which makes the round trip lossless for full sentences.

Everything operates on Unicode code points, so č, ő and even emoji ride the fence intact rather than being split into surrogate halves. The tally shows how many characters travelled and on how many rails.

Like every classical cipher this is a puzzle and a teaching tool, not protection — with at most a few dozen sensible keys, brute force is instant. For actual secrecy use the AES-based encrypt text tool. Everything runs locally in your browser; your message never leaves your device.

FAQ

How do I decrypt a rail fence message?
Set the direction to decrypt and enter the rail count used for encryption — and the offset, if one was used. The tool rebuilds the zigzag, slices the ciphertext into rails and reads the diagonal path back out. Wrong rail counts produce readable-looking garbage, so trying 2 through 6 is the usual approach.
What does the offset do?
It starts the zigzag partway through its cycle instead of at the top rail. Offset 1 begins one step down the descent. Puzzle setters use it as a second key — if a plain decryption fails, try small offsets before giving up on the rail count.
Why does my short message come back unchanged?
With at least as many rails as characters, the zigzag never folds — each character sits on its own rail and reading row by row reproduces the input. Use fewer rails or a longer message.
Should I keep spaces or strip them?
Classic presentations strip whitespace, which also hides word lengths from the solver. Keep spaces when you want a lossless transposition of a full sentence — both directions honor the same setting, so pick one and stay with it.
Is my text uploaded anywhere?
No. The cipher runs entirely in your browser and your message never leaves your device.