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.
create
create("rail-fence")
family
Transposition
options
--rails?
self-inverse
no
keyspace
~n (number of rails)
try it
ciphers rail-fence "WE ARE DISCOVERED" --rails 3

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 - strip them first if the puzzle did. rails is at least 2, default 3.

const railFence = create("rail-fence");
railFence.encode("WEAREDISCOVEREDRUNATONCE", { rails: 3 }).text; // "WECRUOERDSOEERNTNEAIVDAC"
railFence.decode("WECRUOERDSOEERNTNEAIVDAC", { rails: 3 }).text; // "WEAREDISCOVEREDRUNATONCE"
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.

@agntn/ciphers·MIT license· Classical ciphers, for lessons and puzzles. Not for protecting anything, ever.