Ciphers

Running key

Vigenère with a page of a book for a key. The key is as long as the message and never comes round again, so there's no period to find.
IDrunning-key11 / 62classical · polyalphabetic
Cipher / Polyalphabetic

Running key

A page of a book as the key, never repeated.

Keyspace
26^textLength
Decode
same options back
Works on
A-Z, the rest passes
Family
9 in polyalphabetic
required 1 / 1

Options

keystring
required
Passage with at least one ASCII letter per letter of the text; only its letters count, ignoring case

Access

Createcreate("running-key")
CLIciphers encode running-key 'FLEE AT ONCE' --key 'errors can occur in several places'
Tryplayground with the sample above
Kinvigenere, gronsfeld, beaufort, porta +4

Vigenère's weak spot is the keyword going round and round. Running key fixes it the lazy way. The key is as long as the message. Nobody remembers two hundred random letters. But everybody owns a book. Pick a page, pick a line, and the text from there on is the key.

ts
const runningKey = create("running-key");
const page63 = "errors can occur in several places. A label has...";
runningKey.encode("Flee at once. We are discovered", { key: page63 }).text; // "Jcvs rl qnps. Yg uim qawxsmecto"
runningKey.decode("JCVSRLQNPSYGUIMQAWXSMECTO", { key: page63 }).text; // "FLEEATONCEWEAREDISCOVERED"

That's the example on Wikipedia. The key is page 63, line 1 of The C Programming Language. A cipher keyed by K&R. Hard to pick a better book.

How long does the key have to be?

One letter per letter of the text, at least. Only ASCII letters count, on both sides. The spaces and the ... in the K&R line cost nothing. Neither does the punctuation in the message. Letters past the end stay unused, so pass the whole page if you like.

A key that runs out first is an InvalidOptionError with both counts. Why not just wrap around? Because a running key that wraps is plain Vigenère with a long keyword. Handing that back without a word would be a lie.

No key is a MissingOptionError. A key without a single letter is an InvalidOptionError. preserveCase and stripNonAlpha work as in Vigenère.

Where does the next message start?

result.options doesn't echo the passage back. A page of a book in every result wastes everyone's screen. It carries keyUsed instead, the key letters this message took:

ts
runningKey.encode("Flee at once", { key: page63 }).options; // { keyUsed: 10, preserveCase: true, stripNonAlpha: false }

The next message picks up the page from letter eleven. The agent tools take a key of up to 1,000 characters. A whole chapter stays a library call.

Is it unbreakable?

No. Better than Vigenère, though. period still ranks key lengths, but none of them lifts the columns to English. Take a Dickens paragraph keyed with the opening of Moby-Dick. The best length scores an IC of 0.052. LEMON on the same text hits 0.079 at length 5. guess sees several alphabets and lists running key with the other polyalphabetic ciphers. recover has no running key mode, its search wants a key that repeats.

The catch is that the key is English too. Guess a likely word in the message and take it off. Does what's left read like a book? Then you have a piece of both. That's roughly how Bazeries read the dispatches of the Duke of Orléans's conspirators in 1899. Pick a random page all you like. It's still prose.