Autokey
- create
- create("autokey")
- family
- Polyalphabetic
- options
- --key
- self-inverse
- no
- keyspace
- 26^keyLength
- try it
- ciphers autokey "ATTACK AT DAWN" --key QUEENLY
Autokey starts like Vigenère, but the keyword doesn't repeat. Once the primer runs out, earlier plaintext letters supply the shifts. This is the plaintext variant, not ciphertext feedback.
const autokey = create('autokey')
autokey.encode('ATTACKATDAWN', { key: 'QUEENLY' }).text
autokey.decode('QNXEPVYTWTWP', { key: 'QUEENLY' }).text
The results are QNXEPVYTWTWP and ATTACKATDAWN, matching the published example. The effective key begins QUEENLYATTACK. Decoding rebuilds that key from the recovered plaintext, so repeating QUEENLY would give the wrong answer.
Only ASCII letters advance the key. Spaces, punctuation, emoji and other letters pass through unchanged. Lowercase stays lowercase unless preserveCase is false. Set stripNonAlpha to remove everything outside A to Z before processing.
The primer ignores case and characters outside ASCII letters. An absent or empty key raises MissingOptionError. A key with no ASCII letters, or a value that is not a string, raises InvalidOptionError. Each call starts from the primer again.
No repeating keyword, but still no modern security. The plaintext itself is part of the key.