Ciphers

Beaufort

Subtract each letter from a repeating key. The same operation encodes and decodes.
create
create("beaufort")
family
Polyalphabetic
options
--key
self-inverse
yes
keyspace
26^keyLength
try it
ciphers beaufort "DCODE" --key KEY

Standard Beaufort uses (key - input) mod 26, with A = 0. Not variant Beaufort, which subtracts the key from the input. The distinction matters: encode and decode here do exactly the same transformation.

const beaufort = create('beaufort')
beaufort.encode('DCODE', { key: 'KEY' }).text
beaufort.decode('HCKHA', { key: 'KEY' }).text

The results are HCKHA and DCODE, matching the published dCode vector. Only ASCII letters advance the key. Spaces, punctuation and emoji pass through, and lowercase stays lowercase unless preserveCase is false. Set stripNonAlpha to remove everything outside A to Z before processing.

The key 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.

Like Vigenère, a repeating key leaves a period to look for. Reciprocal doesn't mean secure.

@agntn/ciphers·MIT license· Classical ciphers, for lessons and puzzles. Not for protecting anything, ever.