Ciphers

Rail fence

Write the text in a zigzag over N rails, read the rails one after another. A transposition, so the letters never change.
IDrail-fence19 / 72classical · transposition
Cipher / Transposition

Rail Fence

Zigzag over rails, read row by row.

Keyspace
~n
Decode
same options back
Works on
all characters, moved
Family
3 in transposition
required 0 / 1

Options

railsnumber
default 3
Number of rails (2 or more)

Access

Createcreate("rail-fence")
CLIciphers encode rail-fence 'WE ARE DISCOVERED' --rails 3
Tryplayground with the sample above
Kincolumnar, route

The text goes down and up across rails lines and is read off one line at a time. Nothing is substituted, so the histogram of the output is the histogram of the input. Every character counts, spaces included. When the puzzle stripped them first, stripNonAlpha: true does the same, and preserveCase: false uppercases the result. rails is at least 2, default 3.

ts
const railFence = create("rail-fence");
railFence.encode("WEAREDISCOVEREDRUNATONCE", { rails: 3 }).text; // "WECRUOERDSOEERNTNEAIVDAC"
railFence.decode("WECRUOERDSOEERNTNEAIVDAC", { rails: 3 }).text; // "WEAREDISCOVEREDRUNATONCE"
railFence.encode("WE ARE DISCOVERED. RUN AT ONCE.", { rails: 3, stripNonAlpha: true }).text; // same ciphertext
railFence.encode("HELLO", { rails: 1 }); // throws, one rail is the identity

Keyspace is about the length of the text. Try every rail count and read, it takes a minute.