Ciphers

Autokey

A primer starts the key, then the plaintext takes over.
IDautokey10 / 75classical · polyalphabetic
Cipher / Polyalphabetic

Autokey

The plaintext extends the primer key.

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

Options

keystring
required
Primer keyword; only ASCII letters are used, ignoring case

Access

Createcreate("autokey")
CLIciphers encode autokey 'ATTACK AT DAWN' --key QUEENLY
Tryplayground with the sample above
Kinvigenere, gronsfeld, beaufort, porta +9

Vigenère's weak spot is the keyword going round and round. Autokey stops it from repeating. The primer covers the first few letters, then the plaintext itself becomes the key: QUEENLY followed by ATTACK.... This is the plaintext variant, not the one that feeds the ciphertext back.

ts
const autokey = create("autokey");
autokey.encode("ATTACKATDAWN", { key: "QUEENLY" }).text; // "QNXEPVYTWTWP"
autokey.decode("QNXEPVYTWTWP", { key: "QUEENLY" }).text; // "ATTACKATDAWN"
autokey.encode("ATTACK AT DAWN", { key: "QUEENLY" }).text; // "QNXEPV YT WTWP"

Same numbers as the example on Wikipedia. The effective key is QUEENLYATTACK, and decoding has to rebuild it one recovered letter at a time. Repeat QUEENLY instead and you get garbage after the seventh letter, which is a nice way to tell Autokey from Vigenère.

Only ASCII letters advance the key, so the spaces in the last line cost nothing. Lowercase stays lowercase unless preserveCase is false, stripNonAlpha drops everything outside A to Z. The primer ignores case and anything that isn't a letter, a missing one is a MissingOptionError, one with no letters at all an InvalidOptionError. Every call starts from the primer again, there's no state between them.

No period to hunt for, which is progress. But the key is the plaintext, so a good guess at one word of it unlocks the letters after it. Fun for a puzzle. Not for anything else.