Ciphers

Beaufort

Subtract each letter from a repeating key. The same operation encodes and decodes.
IDbeaufort08 / 75classical · polyalphabetic
Cipher / Polyalphabetic

Beaufort

Subtract the text from a repeating key.

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

Options

keystring
required
Repeating keyword, case-insensitive; non-ASCII letters and punctuation ignored

Access

Createcreate("beaufort")
CLIciphers encode beaufort DCODE --key KEY
Tryplayground with the sample above
Kinvigenere, gronsfeld, porta, autokey +9

Looks like a Vigenère turned inside out. Instead of adding the key letter to the text, it takes the text letter away from the key: (key - input) mod 26, with A as 0. Do that twice and you're back where you started, so encode and decode are the same call. That's the standard Beaufort. The variant one subtracts the key from the input, isn't its own inverse, and isn't what this is.

ts
const beaufort = create("beaufort");
beaufort.encode("DCODE", { key: "KEY" }).text; // "HCKHA"
beaufort.decode("HCKHA", { key: "KEY" }).text; // "DCODE"
beaufort.encode("HCKHA", { key: "KEY" }).text; // "DCODE" too, same thing
beaufort.encode("DCODE", { key: "123" }); // throws InvalidOptionError, no letters in the key

HCKHA is the example dCode publishes, so you can check it against something that isn't this library.

Only ASCII letters advance the key. Spaces, punctuation and emoji pass through, lowercase stays lowercase unless preserveCase is false, and stripNonAlpha throws out everything outside A to Z first. The key itself ignores case and anything that isn't a letter. No key at all is a MissingOptionError.

Reciprocal is handy on paper, one table for both directions. It doesn't make it harder to break. The key still repeats, so there's still a period to find, same as Vigenère.