Skip to main content

Rail Fence Cipher

New

Encrypt and decrypt text with the classic Rail Fence transposition cipher, writing letters in a zigzag across a configurable number of rails, with a visual diagram of the pattern.

rail fenceciphertranspositioncryptographyclassical cipher
Read the guide
Shortcuts:⌘ KSearch

Zigzag pattern

The Rail Fence cipher writes letters in a zigzag down and up across a fixed number of "rails" (rows), then reads the result off row by row to produce the ciphertext — a simple transposition cipher that rearranges letters rather than substituting them.

Continue with:

Frequently Asked Questions

How is a transposition cipher different from a substitution cipher?

A substitution cipher (like Caesar or Vigenère) replaces each letter with a different one, while a transposition cipher like Rail Fence keeps every original letter unchanged but rearranges their order — which means letter-frequency analysis alone can't break it, since the letter frequencies of the ciphertext exactly match the plaintext.

How does the zigzag pattern actually work?

Letters are written diagonally downward then upward repeatedly across the chosen number of rails (rows), like a fence rail zigzag; the ciphertext is then produced by reading the letters off row by row rather than in their original zigzag order.

What happens with more rails — does that mean stronger encryption?

More rails does increase the number of possible arrangements, but Rail Fence with any reasonable number of rails is still considered a weak, easily-broken cipher by modern standards since it can typically be cracked just by trying every plausible rail count and checking which result looks like readable text.

Does spacing or punctuation affect the cipher?

This tool strips everything except letters and uppercases the result before processing, matching how the classical cipher is traditionally applied, since spaces and punctuation would otherwise reveal word boundaries in the ciphertext.

Can I see exactly how the zigzag pattern was built?

Yes — the visual diagram below the input shows the exact row each letter landed on, so you can see the diagonal zigzag pattern directly rather than just trusting the final ciphertext output.

Related Tools