Morse Code Translator
  1. Translator
  2. Rail fence cipher

Rail fence cipher decoder

Decode a rail fence cipher by rebuilding its zigzag and reading the letters in order. Enter the ciphertext, rail count, and offset below, or switch to Encode to make a clue.

Decode or encode a rail fence cipher

Everything runs in your browser. Your text stays on this device.

Enable JavaScript to use the tool. The worked grid below is available without it.

How do you decode a rail fence cipher?

Choose Decode, paste the ciphertext, and set the number of rails. Start with offset 0 unless your clue specifies a different starting point. The decoder fills the rails from top to bottom, then reads the message along the zigzag.

Rail fence is a transposition cipher: it rearranges letters instead of replacing them. To encode, write the message diagonally down and up across the rails, then read each row from left to right. The rail count is the key (Arizona State University).

A wooden rail fence crosses a gentle paper meadow beneath a yellow sun.
Illustration: A rail fence across a meadow

Start with the supplied example before pasting a puzzle. Press Convert and compare the result with the worked grid below. If your clue uses groups of five letters for readability, choose A–Z only to remove those grouping spaces. Choose Keep every character only when spaces belong to the encrypted text itself.

What is a rail fence cipher example?

The example below comes from Arizona State University’s teaching sheet: encode “buy your books in August” with three rails (Arizona State University). Our module computes BUYYOURBOOKSINAUGUST as the prepared input and BOOIGUYUBOSNUUTYRKAS as the ciphertext. The displayed rows and counts come from that same calculation.

Follow the zigzag

First 20 of 20 positions, left to right. Rows are numbered from the top. Space = ␣; line break = ↵ or ␍; tab = ⇥.

 1  B       O       O       I       G      
 2    U   Y   U   B   O   S   N   U   U   T
 3      Y       R       K       A       S  
Rail lengths and contents · each row previews up to 80 characters
RailCountContents
15BOOIG
210UYUBOSNUUT
35YRKAS
  1. Start at rail 1. Place one letter in each successive column, moving down to rail 3 and then back up.
  2. Read the occupied positions of rail 1: BOOIG.
  3. Continue with rail 2: UYUBOSNUUT, then rail 3: YRKAS.
  4. Join those rows to get BOOIGUYUBOSNUUTYRKAS. Use that string as the decoder input with the same settings.

This grid is a worksheet you can read without JavaScript. Cover the ciphertext and try reading the rails yourself. Then cover the message and reconstruct it from the rows. The empty grid cells are positions the zigzag never visits; they are not letters to include in your answer.

How do you rebuild the rails when decoding?

Draw the zigzag positions before inserting letters. Count the occupied cells in each row, split the ciphertext at those counts, and fill the rows left to right. Finally, follow the diagonal path to read the original letters. Trinity College demonstrates this row reconstruction (Sophia Knight, Trinity College).

In our computed example the row lengths are 5, 10, 5. Split after the first 5 characters, then after the next 10. Do not divide the ciphertext into three equal pieces: the middle rail has more occupied positions. You can check each split in the tool’s rail table.

Another useful check is the familiar three-rail exercise in Aberystwyth University’s lesson: “We are discovered Flee at once” (Aberystwyth University). Our A–Z mode produces WECRLTEERDSOEEFEAOCAIVDEN. Its rail lengths are 7, 12, 6. This longer example lets you check that a decoder handles the final, incomplete zigzag without adding filler letters.

How does a rail fence cipher with offset work?

On this page, offset means the number of positions skipped along the ordinary top-start zigzag before placing the first character. This matches dCode’s illustrated positive-offset convention (dCode). It is a starting phase, not an instruction to discard characters from your message.

For three rails, this tool’s cycle is four steps: rails 1, 2, 3, 2, then back to 1. Offset 1 starts on rail 2 moving down; offset 3 starts on rail 2 moving up. Our module encodes ABCDE with three rails and offset 1 as DACEB; the rail contents are D / ACE / B.

The accepted offsets run from zero through one less than the cycle length, calculated as 2 × (rails − 1). With one rail, only offset zero is allowed. If another tool labels its setting “starting row,” compare the direction too. Two starts on the same middle rail can follow different paths. Record both rail count and offset when you share a clue.

What happens to spaces, punctuation, J, I and X?

These are this tool’s rules. A–Z mode removes everything except English letters and converts them to uppercase. It cannot restore the original word breaks or capitalization. Keep mode preserves case and every character, including line breaks, and moves those characters through the rails. Select the same mode in both directions for a round trip.

J and I remain separate. X is an ordinary letter: the tool never inserts or strips padding. You do not need to complete the last diagonal. If a puzzle author added filler, remove it only when their instructions explain how. Save the original ciphertext before editing a suspected typo or deleting a trailing character.

Can you decode rail fence without knowing the rails?

You can try different rail counts and inspect the results; ASU describes exhaustive key testing as feasible for this cipher (Arizona State University). This tool converts one setting at a time. It does not rank candidates, recognize English, or certify that a readable phrase is the intended answer.

Try offset zero first and keep a short list of settings you have checked. If nothing reads sensibly, revisit the transcription and text mode before testing offsets. A missing letter changes the shape you reconstruct. For a different kind of clue, compare the Caesar cipher decoder or Vigenère cipher decoder; those tools have their own key instructions.

How can you send rail fence ciphertext in Morse?

For a puzzle hunt or escape room you design, try this two-stage clue. Our encoder turns OPEN GATE into OGPNAEET using three rails and offset zero. The widget sends those ciphertext letters using the international Morse signals specified by (ITU-R M.1677-1).

Recover the Morse letters, then decode them with three rails and offset zero.

Use the Morse code translator or the Morse code alphabet to recover the letters first. Then paste them here. Give your players the rail count as a separate hint so they can distinguish the two stages. The Is Morse code a cipher? guide explains the role of the signal alphabet.

Where does the rail fence cipher come from?

ASU’s historical note records rail fence use as a field cipher by both sides in the US Civil War (Arizona State University).

Use the tool for exercises and constructed clues. Trinity College explains that the fixed rail patterns make brute-force analysis straightforward (Sophia Knight, Trinity College). For your own puzzle, test the full solve in reverse before sharing it: Morse back to letters, letters back through the rail fence, then add word breaks for the final answer.

Sources

  1. Rail Fence Ciphers. Arizona State University, checked 20 November 2026.
  2. The Rail Fence Cipher. Sophia Knight, Trinity College, checked 20 November 2026.
  3. Transposition Ciphers. Aberystwyth University, checked 20 November 2026.
  4. Rail Fence: variants and offset. dCode, checked 20 November 2026.
  5. Recommendation ITU-R M.1677-1, International Morse code. ITU Radiocommunication Sector, October 2009.