Ciphers
Vigenère
A keyword picks a different Caesar shift for each letter. Keyspace 26 to the key length, weakness is the period.
- create
- create("vigenere")
- family
- Polyalphabetic
- options
- --key
- self-inverse
- no
- keyspace
- 26^keyLength
- try it
- ciphers vigenere "ATTACK AT DAWN" --key LEMON
The keyword repeats under the plaintext and each letter is shifted by the key letter above it, A meaning 0. Only letters advance the key. Spaces and punctuation pass through without eating a key position, which is why "ATTACK AT DAWN" and "ATTACKATDAWN" agree letter for letter. Key is letters only, case doesn't matter.
const vigenere = create("vigenere");
vigenere.encode("ATTACK AT DAWN", { key: "LEMON" }).text; // "LXFOPV EF RNHR"
vigenere.encode("ATTACK AT DAWN", { key: "LEMON", stripNonAlpha: true }).text; // "LXFOPVEFRNHR"
vigenere.decode("LXFOPV EF RNHR", { key: "LEMON" }).text; // "ATTACK AT DAWN"
vigenere.encode("HELLO"); // throws MissingOptionError: key
Keyspace is 26 to the key length, which sounds like a lot until you notice that every n-th letter is a plain Caesar. So the attack is finding the period. analyzeFrequency on the whole text gives an IC near 0.038; on every fifth letter of the LEMON example it climbs back toward English.
Trithemius is a Vigenère whose key is the alphabet itself.