Home

railfence

Railfence, or the rail fence cipher, is a classical transposition cipher used in cryptography. It does not substitute letters but reorders them by writing the plaintext in a zigzag across a fixed number of rails (rows). After the text is laid out, the letters are read off row by row to produce the ciphertext.

Encryption involves choosing the number of rails. The plaintext is written diagonally down the rails, moving

Example: with three rails and the plaintext WEAREDISCOVER (no spaces), placing letters in a zigzag yields rail

Decryption reverses the process: given the number of rails and the ciphertext, reconstruct the zigzag pattern

Security and usage: the rail fence cipher offers little real security and can be broken by simple

History and variants: the exact origins are unclear, but the method appears in classical and later cryptography

from
the
top
rail
to
the
bottom
and
then
back
up,
in
a
repeating
zigzag
until
all
characters
are
placed.
The
ciphertext
is
then
obtained
by
concatenating
the
letters
from
rail
1,
then
rail
2,
and
so
on.
Typically,
spaces
and
punctuation
are
removed
in
practice.
1:
W
E
C
R,
rail
2:
E
R
D
S
O
E,
rail
3:
A
I
V.
Reading
the
rows
in
order
gives
the
ciphertext
WECRERDSOEAIV.
and
fill
in
letters
by
rail
in
order,
then
read
along
the
zigzag
path
to
retrieve
the
plaintext.
analysis
or
brute
force,
especially
for
short
messages.
It
is
mainly
of
historical
and
instructional
value,
used
to
illustrate
transposition
techniques
and
to
serve
in
puzzles.
texts
as
a
simple
teaching
tool.
Variants
include
different
rail
counts
and
multi-pass
schemes
to
increase
complexity
modestly.