Security

Rail Fence Cipher

Encrypt and decrypt text with the rail fence transposition cipher using a chosen number of rails. A classic zigzag cipher.

Last reviewed by the Radiatus Cloud team

Encrypt and decrypt text with the rail fence zigzag transposition cipher.

Need this handled by experts?

Radiatus runs VAPT, managed SOC & security engineering for regulated teams.

Book a free security consult

Encrypt with the rail fence cipher

The rail fence cipher is a transposition cipher that rearranges the letters of a message rather than substituting them. The text is written in a zigzag pattern across a chosen number of rails, or rows, and then read off row by row to produce the ciphertext. With three rails, the message HELLOWORLD becomes HOLELWRDLO. Decryption reconstructs the zigzag pattern and reads the letters back in their original order.

The number of rails is the key, and more rails produce a more thorough scramble for longer messages.

A classic transposition

Because it only reorders letters, the rail fence cipher preserves the letter frequencies of the original, which makes it weak against analysis, but it is a wonderful introduction to the idea of transposition ciphers. It appears often in puzzles, escape rooms and cryptography lessons. The zigzag pattern is easy to draw by hand, which historically made it practical for quick field use.

Like other classical ciphers, it offers no real security and must not protect sensitive data. It works on the characters as given, including spaces. All processing happens locally in your browser.

Privacy and usage

Because the rail fence cipher runs entirely in your browser, nothing you enter is uploaded or stored, so you can use it with sensitive values safely. The output is generated locally and never transmitted, and you can run the tool as many times as you need for free.

Related tools

  • Password Strength Checker — Measure password strength by entropy and pattern analysis rather than character-class rules. Checked entirely in your browser.
  • Password Generator — Generate strong random passwords and passphrases in your browser using the Web Crypto API. Nothing is transmitted, logged or stored.
  • Hash Generator — Generate MD5, SHA-1, SHA-256 and SHA-512 hashes in your browser. Compare checksums and verify file integrity with nothing uploaded to a server.
  • Base64 Encoder/Decoder — Encode and decode Base64 in your browser, including URL-safe Base64 and UTF-8 text. Handles files and data URIs locally with nothing uploaded.

Frequently Asked Questions

How does the rail fence cipher work?

The message is written in a zigzag across a set number of rails and then read off row by row, rearranging the letters without changing them.

What is the key?

The number of rails. More rails create a more thorough rearrangement, and the recipient needs the same number to decrypt.

Is it a substitution cipher?

No. It is a transposition cipher: it reorders the existing letters rather than replacing them with different ones.

Is the rail fence cipher secure?

No. It preserves letter frequencies and is easily broken, so it is for learning and puzzles rather than real security.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Enter text and the number of rails, then encrypt or decrypt.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.