🪜 Rail Fence Cipher
Write the message in a zigzag across several rails, then read each rail in turn — the rail fence transposition cipher, with 2–10 rails.
Transformed in your browser — nothing you type is uploaded.
How the rail fence cipher works
Unlike substitution ciphers (which replace letters), the rail fence is a transposition cipher — it keeps the letters but scrambles their order. You write the message diagonally down and up across a set number of "rails", then read off each rail left to right to form the ciphertext. Decoding reverses the zigzag. The number of rails is the key; this tool lets you set 2 to 10.
Because it only rearranges letters, the ciphertext contains exactly the same letters as the plaintext — which is a giveaway, and with so few possible rail counts it's easily brute-forced. It's a classic teaching example of transposition and a common puzzle cipher, not a secure method. Spaces and punctuation are shuffled along with the letters, so results are cleanest on continuous text.
Frequently asked questions
What is a transposition cipher?
One that rearranges the order of the letters rather than replacing them (as a substitution cipher does). The rail fence is a classic example — same letters, scrambled positions.
How does the rail fence pattern work?
You write letters diagonally down then up across the rails, forming a zigzag, then read each rail's letters in order. With 3 rails, "HELLO" is written on a zigzag and read row by row to produce the cipher.
What is the key?
The number of rails. More rails scramble the text more, but there are only a handful of sensible values, which is why the cipher is easy to crack by trying each.
Is the rail fence cipher secure?
No — it preserves the exact letters and has very few keys, so it's quickly broken. It's valued for teaching transposition and for puzzles, not for security.
Does it run locally?
Yes — the zigzag arithmetic is done in your browser; nothing is uploaded.