ZIGZAG TRANSPOSITION • BEGINNER

Rail Fence Cipher

Write letters diagonally across rails, then read each rail to rearrange the message.

Family Transposition
Key / parameter Number of rails
Text structure Letters are rearranged, not substituted
01 • OVERVIEW

What is the Rail Fence Cipher?

Rail Fence is a transposition cipher. The actual letters do not change; only their positions do.

To encrypt, the plaintext is written in a zigzag down and up across a chosen number of rails. The ciphertext is formed by reading the rails row by row.

Competition note

The cipher mechanics on this page are self-contained. Science Olympiad event formats, allowed variants, and tournament constraints can change by season; the current official Rules Manual and official clarifications take precedence.

Starting from zero?

No outside reference is assumed. Work through Foundations → Complete Reference → Encryption → Decryption in order, then use the competition and cryptanalysis sections.

02 • FOUNDATIONS

What you need to know

  • A rail is one row of the zigzag.
  • For r rails, the basic zigzag cycle length is 2(r−1).
  • Spaces are commonly removed before arranging the letters.

Beginner glossary

Term Meaning
Rail One horizontal row of the zigzag.
Zigzag The down-then-up path used to place plaintext letters.
Cycle length For r rails, the rail pattern repeats every 2(r−1) positions.
Transposition A cipher that rearranges letters instead of replacing them.
03 • COMPLETE REFERENCE

Keep this beside you while solving

3 rails pattern: 0: S . . . E . . . E . . . 1: . E . R . T . E . S . A 2: . . C . . . M . . . S .

Rail paths you can sketch quickly

Rails Repeating rail-number path Cycle length
2 1 2 1 2 … 2
3 1 2 3 2 … 4
4 1 2 3 4 3 2 … 6
5 1 2 3 4 5 4 3 2 … 8
Decryption principle: do not guess where ciphertext letters go. First draw/mark the zigzag positions, count positions on each rail, fill each rail from the ciphertext, then trace the zigzag.
Reference rule: if a fixed table, formula, alphabet, or convention is needed to solve this cipher, it should be visible in this section or generated explicitly by the visualizer below.
04 • ENCRYPTION

How encryption works

1

Remove separators if required

Use a continuous letter stream.

2

Draw the zigzag

Move downward one rail per letter, then reverse direction at the bottom.

3

Fill every letter

Continue the up/down pattern to the end.

4

Read across rails

Top rail first, then the next rail, until all letters are collected.

05 • DECRYPTION

How decryption works

1

Determine the rail count

This defines the zigzag path.

2

Mark the path positions

Draw placeholders in the zigzag for the ciphertext length.

3

Fill rail by rail

Place ciphertext letters into the marked positions across each rail.

4

Read the zigzag

Follow the path down and up to recover plaintext order.

06 • COMPETITION WORKFLOW

How to approach it in Codebusters practice

  • Do not treat Rail Fence like substitution—letter frequencies are unchanged.
  • The rail count may be supplied or inferred by testing plausible rail counts.
  • A clean grid prevents most errors.

What the problem gives you vs. what you produce

Part What to expect
You may be given Ciphertext and the number of rails, or a ciphertext where a small range of rail counts can be tested.
You must find The reordered plaintext.
Fastest first move Draw the rail-number path before placing any letters.
Season note: use this page to learn the cipher mechanics and solving workflow. Exact Science Olympiad event constraints can change by season, so follow the current official rules/clarifications for tournament-specific limits.
07 • CRYPTANALYSIS

How to attack an unknown or partially known key

  • Try small rail counts first; practical puzzles usually use a manageable number of rails.
  • Look for likely word fragments after reconstructing each candidate rail count.
  • Because all original letters remain, unusual letter-frequency distributions are not created by the cipher itself.
08 • WORKED PROBLEM

Follow one example from start to finish

Plaintext
WEAREDISCOVERED
Rails
3
Zigzag
Write W-E-A-R-E… down/up across three rows.
Read rails
WECRERDSOEEAIVD
BEGINNER SELF-CHECK

Before moving on, make sure you can answer these without another site:

  • Can you write the rail path for 4 rails without drawing letters?
  • Can you explain why decryption must fill rail positions before following the zigzag?
09 • ERROR CHECK

Common mistakes

!

Reading diagonally instead of row-by-row during encryption.

!

Changing direction one position too early.

!

Forgetting that the top and bottom rails contain fewer positions.

!

Inserting spaces into the grid as if they were letters when the problem removed them.

10 • SPEED

Competition speed strategies

1

Draw rail numbers 0,1,2,… beside the grid.

2

For decryption, mark the zigzag shape first before placing any ciphertext letters.

3

Use cycle length 2(r−1) to predict top/bottom positions.

11 • QUICK REFERENCE

What to remember under time pressure

Family Transposition
Key Number of rails
Cycle 2(r−1)
Letters changed? No—only positions change
How to use this section: during timed practice, come here first for the minimum rules. If a step is unclear, jump back to Complete Reference or the worked example instead of guessing.
12 • INTERACTIVE LAB

See every transformation

Use the lab to change inputs and keys, keep the relevant reference material visible, inspect each intermediate transformation, and then read the “How to reverse it” panel so encryption and decryption connect.