1001Ferramentas
🚆Security

Rail Fence Cipher

Encrypts messages with the Rail Fence (zigzag) cipher, spreading letters across N rails and reading rail by rail. A classic transposition cipher for learning cryptography.

Cifrado

The zigzag across rails, without paper

An escape room puzzle, a geocaching hint or a classroom exercise asking for a transposition cipher on N rails. You can draw it by hand, but it is easy to miss a turn in the zigzag and burn ten minutes checking. Type the phrase, pick how many rails you want, and the ciphertext appears below, updating as you type. With the default example, OLA MUNDO on 3 rails comes out as OMOL UDAN.

The mechanic is writing letters down and up across the lines, then reading line by line from top to bottom. Two details people miss: the space travels through the zigzag like any other character, so it resurfaces in an odd position and hands an attacker a clue. And if the rail count is equal to or larger than the text length, the path never folds and the output is identical to the input. The minimum is 2 rails, and decimal values get rounded.

This page only encrypts. There is no decrypt mode, so going back means redoing the path by hand: work out how many letters land on each rail, cut the sequence into those chunks and read along the diagonal. The text field is a single line, so paragraphs with line breaks are out. Puzzle writers usually strip spaces and accents before encoding. The whole calculation happens in your browser, with nothing sent anywhere.

Frequently asked questions

How do I decrypt a Rail Fence message?
Rebuild the zigzag: the text length and rail count tell you how many letters sit on each line, so you cut the sequence into those blocks and read diagonally. This page only handles the encoding direction.
How many rails should I use?
Two or three is the puzzle classic. More rails scramble further up to a point, but once the count approaches the text length the cipher stops scrambling and returns the original phrase.
Is Rail Fence substitution or transposition?
Transposition. The letters stay the same and only change position, so letter frequencies match the plaintext exactly. That is precisely what gives the cipher away under analysis.

Related Tools