Skip to content

Rail Fence Cipher Decoder

Encrypt or decrypt text with the historical Rail Fence zigzag transposition while preserving every Unicode code point.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Choose encrypt or decrypt and enter a whole-number rail count from 2 to 100.
  2. 2.Paste the exact text, including any spaces, punctuation or line breaks that must participate.
  3. 3.Run and copy the result; use the identical convention and rail count for the reverse operation.

About Rail Fence Cipher Decoder

Rail Fence Cipher Decoder implements the classic zigzag transposition cipher for two through one hundred rails. Enter plaintext to write characters diagonally down and up across rows, then read each row from top to bottom. Decrypt mode reconstructs the same zigzag positions and restores the original order.

Unlike substitution ciphers, Rail Fence does not replace characters. It changes only their positions. With three rails, WEAREDISCOVEREDFLEEATONCE becomes WECRLTEERDSOEEFEAOCAIVDEN. The row pattern is 0,1,2,1 and repeats with cycle length two times rails minus one.

The page preserves uppercase and lowercase letters, digits, whitespace, punctuation and emoji. It iterates Unicode code points, preventing an emoji from being split into two UTF-16 surrogate halves. It does not remove spaces or normalize text. This explicit behavior can differ from classroom examples that first strip non-letters.

Encryption creates one ordered bucket for each rail and appends each code point according to its zigzag row. Decryption first counts how many positions belong to every rail, slices the ciphertext by those counts, and consumes one character from the appropriate row for each original position. No guessed padding is involved.

If the rail count equals or exceeds the number of characters, every used position lies on a separate initial descent and the output remains unchanged. The tool still validates that rails is a whole number from 2 to 100. Input is capped at 200,000 code points so row construction and reconstruction remain responsive.

Rail Fence is a historical teaching cipher, not modern encryption. It has no secret beyond a small rail count, preserves character frequencies and is easy to brute force. Do not use it for credentials, personal data, tokens, files or confidential communication. AES-GCM or another reviewed authenticated-encryption construction is appropriate for real security.

Eight golden fixtures cover the canonical message, two through four rails, another alphabetic phrase, digits, spaces, punctuation and supplementary Unicode. Each expected ciphertext is asserted directly, then decrypted back to the exact original. Invalid rail counts and empty inputs are separate failures rather than silent defaults.

Some variants add an initial offset, reverse the direction, start from the bottom rail or remove spaces before arranging characters. This page uses no offset, starts at the top, moves downward first and preserves all code points. Confirm those conventions before comparing output from another exercise or website.

Use encrypt mode by entering exact plaintext and the agreed rail count. Copy the resulting sequence without trimming whitespace. For decryption, use the same rail count and unmodified ciphertext. Treat a successful round trip as confirmation of the convention only, never as evidence of cryptographic confidentiality or authenticity.

Because transformation is deterministic, identical input and rail count always give identical output. The interface retains visible formatting inside the result block, and the copy action writes the exact string. Line breaks participate as characters and therefore change every later position in the zigzag. Decryption never guesses a rail count; trying alternatives is a separate cryptanalysis task.

Methodology & sources

For index i, the rail is p when p=i mod 2(r-1) is below r, otherwise 2(r-1)-p. Encryption groups by rail; decryption counts that same pattern, slices ciphertext into rail buckets, then consumes them in positional order.

Frequently asked questions

Encoding & Crypto guides

View all