ℹ️ About Rail Fence Cipher
Rail Fence Cipher, also called the zigzag cipher, is a classical transposition cipher: it keeps the original characters but changes their positions. Plaintext is written diagonally across a chosen number of rails, reverses direction at the top and bottom rail, and is then read row by row to produce the ciphertext.
Use this Rail Fence encoder and decoder for CTF warmups, classroom cryptography exercises, puzzle hunts, geocaching clues, and demonstrations of how transposition differs from substitution ciphers such as Caesar, ROT13, Atbash, and Vigenere. The rail count acts as the key, so both sender and recipient must use the same number of rails and the same space-handling rule.
How rail fence encryption works: with 3 rails, the message moves down rail 1 -> rail 2 -> rail 3, then back up rail 2 -> rail 1, repeating until all characters are placed. Decryption reconstructs the same zigzag path, fills each rail with the ciphertext characters, and reads the path in order to recover the plaintext.
Plaintext: WE ARE DISCOVERED Rails: 3 W E C R D E A E D S O E E R I V R Ciphertext: WECRDEAEDSOEERIVR
Practical rail fence variants may preserve spaces and punctuation, remove them before processing, or group the output into blocks. Those choices change the visible ciphertext, so note the settings when sharing an encoded message.
Strength rating: historical and educational only. Rail Fence is not suitable for protecting passwords, API keys, private messages, or regulated data. It preserves letter frequency and has a small key space, so a short script or manual trial of likely rail counts can often recover readable text. Use modern authenticated encryption for real confidentiality.
Source references: Britannica's overview of transposition ciphers, the American Cryptogram Association Railfence cipher notes, and Trinity College's historical Rail Fence Cipher explanation.
API Usage Example:
POST /api/tools/encoding-decoding/railfence
Content-Type: application/json
{
"text": "Hello World",
"operation": "encode",
"rails": 3,
"remove_spaces": false
}