The Beaufort cipher is a polyalphabetic substitution cipher invented by Sir Francis Beaufort. It is closely related to the Vigenère cipher but is reciprocal: the same keyword and the same operation both encrypt and decrypt. That symmetry made it convenient for mechanical cipher devices, and it remains a neat illustration of self-inverse encryption.
How it works
Each letter is turned into a number from 0 (A) to 25 (Z). The keyword repeats across the message, supplying a key letter K for each text letter P. The output letter is computed as:
C = (K - P) mod 26
Subtracting the plaintext value from the key value is the crucial detail. In the Vigenère cipher the rule is C = (P + K) mod 26, which is not its own inverse, so decryption needs the opposite subtraction. In Beaufort, applying (K - P) mod 26 a second time to the ciphertext returns the original plaintext, because K - (K - P) = P. This is why there is only one operation: encrypting and decrypting are the same.
Only letters are enciphered, and they advance the keyword. Spaces, digits and punctuation are copied straight through and do not consume a keyword position, so the keyword stays aligned with the letters of the message.
Example
Encipher the letter A (P=0) with key letter K (K=10): C = (10 − 0) mod 26 = 10, which is K. Encipher G (P=6) with the same key letter: C = (10 − 6) mod 26 = 4, which is E. Feeding those ciphertext letters back through the same keyword recovers A and G.
Notes
- Choose a long, non-obvious keyword: short or dictionary keywords are easy to attack.
- Beaufort should not be confused with the “variant Beaufort”, which uses
C = (P − K) mod 26and is not reciprocal. - For a cipher whose key extends itself with the message, try the Autokey cipher.