Advertisement

Rail fence cipher

Encrypt and decrypt with the rail fence transposition cipher. Choose the number of rails; letters zigzag down and across the rails.

Encrypt or decrypt

The rail fence is a transposition cipher: letters zigzag across rails, then each rail is read in order.

Nothing is uploaded. Everything is computed locally in your browser.
Rail fence

The result appears below.

-
Advertisement

Zigzag transposition

The rail fence writes the message diagonally across a chosen number of rails, bouncing up and down, then reads each rail left to right. With 3 rails, WEAREDISCOVERED becomes WECRLTEERDSOEEFEAOCAIVDEN. The letters are only rearranged, never substituted, which makes it a transposition cipher.

Breaking it

The key space is tiny: only the rail count matters, and counts above half the message length are equivalent to smaller ones. Trying every rail count from 2 upward breaks any message in seconds, and anagramming finishes the job. It is a puzzle cipher, not protection.

Rail Fence Cipher FAQs

How many rails should I use?
Anything from 2 up to about half the message length. More rails is not much stronger; the cipher falls to brute force regardless, so pick what looks fun.
Rail fence vs Caesar cipher?
Rail fence rearranges letters (transposition) while Caesar substitutes them. Both are classical teaching ciphers with tiny key spaces.
Can I decrypt without knowing the rails?
Yes, try rail counts from 2 upward until readable text appears. This tool decrypts with the count you enter.
Does it change letter frequency?
No. Transposition preserves every character count, so frequency analysis of the ciphertext matches the plaintext language.
Offline?
Yes, pure JavaScript with no libraries and no uploads.
Advertisement