The Beaufort cipher looks, at first glance, like a close relative of the Vigenère cipher. It uses a keyword, repeats that keyword across the message, turns letters into numbers, and works inside the circular arithmetic of the alphabet. But one small reversal changes the whole character of the cipher.
Vigenère adds the key to the plaintext. Beaufort subtracts the plaintext from the key.
That means the Beaufort cipher uses the rule:
C = (K - P) mod 26
where P is the plaintext letter, K is the key letter, and C is the ciphertext letter.
That minus sign is the cipher's identity. It makes Beaufort a reciprocal cipher. The same operation that encrypts a message also decrypts it. If you put plaintext through Beaufort with the correct key, you get ciphertext. If you put that ciphertext through Beaufort again with the same key, the original plaintext returns. That gives the cipher a satisfying symmetry.
It is not secure by modern standards. Like other repeated-key classical ciphers, it leaks patterns and can be attacked. But as a teaching cipher, Beaufort is excellent. It shows how polyalphabetic substitution works, how modular arithmetic handles letters, how a repeated keyword changes the alphabet as the message progresses, and how a cipher can be designed so that one operation undoes itself.
Caesar shifts the alphabet. Vigenère rotates it with a keyword. Beaufort reflects it.
Beaufort cipher at a glance
| Feature | Beaufort Cipher |
|---|---|
| Type | Polyalphabetic substitution cipher |
| Main idea | Use a repeating keyword with the rule C = K - P mod 26 |
| Direction | Reciprocal |
| Formula | C = (K - P) mod 26 |
| Alphabet numbering | A = 0, B = 1, C = 2, ..., Z = 25 |
| Key | A repeated keyword |
| Common example key | FORTIFICATION |
| Example | ATTACK AT DAWN -> FVYTGV IJ XTMB |
| Key advancement | Usually advances only when a letter is processed |
| Decryption | Same Beaufort operation with the same key |
| Closest relative | Vigenère cipher |
| Common confusion | Standard Beaufort vs Variant Beaufort |
| Security | Educational only; weak by modern standards |
| Best use | Learning polyalphabetic substitution, reciprocal ciphers, and modular arithmetic |
The Beaufort cipher is often introduced after Vigenère because it uses the same general machinery: a repeated keyword and a changing substitution alphabet. But Beaufort's key-minus-plaintext rule gives it a different feel and a different mathematical structure.
That is why it deserves its own article. It is not merely "another Vigenère". It is Vigenère turned around.
What is the Beaufort cipher?
The Beaufort cipher is a classical polyalphabetic substitution cipher.
That means it replaces letters with other letters, but it does not use the same substitution alphabet for the whole message. Instead, the substitution changes according to a repeating keyword.
A monoalphabetic cipher, such as Caesar or Atbash, uses one fixed rule.
| Plaintext | Ciphertext |
|---|---|
| A | D |
| B | E |
| C | F |
Once the mapping is set, each plaintext letter always becomes the same ciphertext letter.
The Beaufort cipher works differently. It uses a keyword, such as:
FORTIFICATION
That keyword is repeated across the message:
FORTIFICATIONFORTIFICATIONFORTIFICATION...
Each key letter changes how the matching plaintext letter is encrypted. So the same plaintext letter can become different ciphertext letters in different places. That is the major advantage of polyalphabetic substitution over simple substitution.
But Beaufort has one special feature that makes it stand apart from Vigenère.
It is reciprocal.
Encryption and decryption use the same kind of operation:
output = key - input mod 26
When the input is plaintext, the output is ciphertext. When the input is ciphertext, the output is plaintext.
That is the clean, central idea of the Beaufort cipher.
How Beaufort works
The Beaufort cipher begins by turning letters into numbers. The usual convention is:
| Letter | A | B | C | D | E | F | G | H | I | J | K | L | M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| Letter | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Number | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
Once the letters have numbers, Beaufort applies this formula:
C = (K - P) mod 26
| Symbol | Meaning |
|---|---|
P |
Plaintext letter number |
K |
Key letter number |
C |
Ciphertext letter number |
mod 26 |
Wrap the result around the 26-letter alphabet |
Suppose the plaintext letter is A. A = 0.
Suppose the key letter is F. F = 5.
Apply the Beaufort rule:
C = (K - P) mod 26
C = (5 - 0) mod 26
C = 5
5 = F, so:
A with key F becomes F
Now try a slightly less obvious example.
Plaintext letter:
T
T = 19.
Key letter:
O
O = 14.
Apply the rule:
C = (14 - 19) mod 26
C = -5 mod 26
C = 21
21 = V, so:
T with key O becomes V
This is the first place the cipher starts to feel different from ordinary subtraction. Beaufort works on a circular alphabet. If the subtraction goes below A, it wraps around from Z.
It is the same idea as clock arithmetic. If it is 3 o'clock and you subtract 5 hours, you do not stop because the number has gone below zero. You wrap around the clock.
The alphabet is Beaufort's clock face.
Key and rules
The Beaufort cipher uses a keyword. For example:
FORTIFICATION
The keyword is repeated over the letters of the message:
| Plaintext | A | T | T | A | C | K | A | T | D | A | W | N |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | F | O | R | T | I | F | I | C | A | T | I | O |
If the message is longer than the key, the key starts again from the beginning. So the key stream becomes:
FORTIFICATIONFORTIFICATIONFORTIFICATION...
The main practical rules are:
| Rule | Explanation |
|---|---|
| Use a keyword | The keyword supplies the changing key letters |
| Repeat the keyword | The key repeats until it covers the whole message |
| Convert letters to numbers | A = 0 through Z = 25 |
| Use the Beaufort formula | C = K - P mod 26 |
| Advance the key only on letters | Spaces and punctuation usually do not consume key letters |
| Preserve or remove formatting by choice | Tools may preserve case, punctuation, numbers, or group letters |
| Use the same operation to decrypt | Beaufort is reciprocal |
The rule about key advancement matters.
If the message is:
ATTACK AT DAWN
the cipher normally ignores the space when advancing the key. So the key aligns with the letters like this:
| Plaintext letters only | A | T | T | A | C | K | A | T | D | A | W | N |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | F | O | R | T | I | F | I | C | A | T | I | O |
The space in ATTACK AT DAWN does not use up a key letter. That is the behaviour the Beaufort tool describes: the key advances only when the input character is a letter.
This makes the tool easier to use. A user can type a normal phrase with spaces and punctuation without accidentally changing the whole key alignment.
Classical ciphertext is often grouped into blocks, such as groups of five letters:
FVYTG VIJXT MB
That looks more traditional and hides word lengths. But grouping is only formatting. The actual cipher is still the same formula.
Worked example: ATTACK AT DAWN
Now encrypt:
ATTACK AT DAWN
using the key:
FORTIFICATION
First, ignore the spaces for the letter-by-letter operation:
ATTACKATDAWN
Now repeat the key across the plaintext letters:
| Plaintext | A | T | T | A | C | K | A | T | D | A | W | N |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | F | O | R | T | I | F | I | C | A | T | I | O |
Now convert each plaintext letter and key letter into numbers. Then apply:
C = (K - P) mod 26
| Plain | P | Key | K | Calculation | C | Cipher |
|---|---|---|---|---|---|---|
| A | 0 | F | 5 | 5 - 0 = 5 |
5 | F |
| T | 19 | O | 14 | 14 - 19 = -5 ≡ 21 |
21 | V |
| T | 19 | R | 17 | 17 - 19 = -2 ≡ 24 |
24 | Y |
| A | 0 | T | 19 | 19 - 0 = 19 |
19 | T |
| C | 2 | I | 8 | 8 - 2 = 6 |
6 | G |
| K | 10 | F | 5 | 5 - 10 = -5 ≡ 21 |
21 | V |
| A | 0 | I | 8 | 8 - 0 = 8 |
8 | I |
| T | 19 | C | 2 | 2 - 19 = -17 ≡ 9 |
9 | J |
| D | 3 | A | 0 | 0 - 3 = -3 ≡ 23 |
23 | X |
| A | 0 | T | 19 | 19 - 0 = 19 |
19 | T |
| W | 22 | I | 8 | 8 - 22 = -14 ≡ 12 |
12 | M |
| N | 13 | O | 14 | 14 - 13 = 1 |
1 | B |
Now put the ciphertext letters together:
FVYTGV IJ XTMB
So:
ATTACK AT DAWN -> FVYTGV IJ XTMB
This is the example used in the Beaufort tool.
The example shows the main difference between Beaufort and a simple substitution cipher. The plaintext letter A appears several times, but it does not always become the same ciphertext letter.
| Plaintext letter | Key letter | Ciphertext |
|---|---|---|
| A | F | F |
| A | T | T |
| A | I | I |
| A | T | T |
The same plaintext letter changes depending on the key letter above it. That is the point of a polyalphabetic cipher.
It breaks the simple one-letter-to-one-letter pattern that makes Caesar, Atbash, and ordinary monoalphabetic substitution so vulnerable. But it does not remove all patterns.
The keyword still repeats. And repetition is dangerous.
Decrypting Beaufort: the same rule again
The Beaufort cipher is reciprocal. That means the same kind of operation is used for both encryption and decryption.
Encryption:
C = (K - P) mod 26
Decryption:
P = (K - C) mod 26
Those formulas look almost the same. That is because the operation undoes itself.
Suppose we encrypt a plaintext letter:
C = K - P
Now apply Beaufort again to the ciphertext:
K - C
Substitute the expression for C:
K - (K - P)
Now simplify:
K - K + P = P
The original plaintext comes back.
That is the mathematical heart of Beaufort. It is like a mirror: reflect something once and it is reversed; reflect it again and it returns to its original form.
Now decrypt the example.
Ciphertext:
FVYTGV IJ XTMB
Key:
FORTIFICATION
Write the key above the ciphertext letters:
| Ciphertext | F | V | Y | T | G | V | I | J | X | T | M | B |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Key | F | O | R | T | I | F | I | C | A | T | I | O |
Now apply:
P = (K - C) mod 26
Start with the first letter. Ciphertext F = 5. Key F = 5.
P = (5 - 5) mod 26
P = 0
0 = A, so F -> A.
Second letter: ciphertext V = 21, key O = 14.
P = (14 - 21) mod 26
P = -7 mod 26
P = 19
19 = T, so V -> T.
Third letter: ciphertext Y = 24, key R = 17.
P = (17 - 24) mod 26
P = -7 mod 26
P = 19
19 = T, so Y -> T.
Continue the same process and the plaintext returns:
FVYTGV IJ XTMB -> ATTACK AT DAWN
That is why Beaufort is so neat. The tool does not need one mathematical rule for encryption and a completely different one for decryption. The same operation does both jobs.
Beaufort, Vigenère, and Variant Beaufort
The Beaufort cipher is often confused with two related systems: the Vigenère cipher and the Variant Beaufort cipher.
That confusion is understandable. All three use alphabet numbers, modular arithmetic, and a repeated keyword.
But the formulas are different.
| Cipher | Encryption formula | Decryption formula | Reciprocal? |
|---|---|---|---|
| Vigenère | C = P + K mod 26 |
P = C - K mod 26 |
No |
| Beaufort | C = K - P mod 26 |
P = K - C mod 26 |
Yes |
| Variant Beaufort | C = P - K mod 26 |
P = C + K mod 26 |
No |
This table is worth reading carefully.
Vigenère adds the key:
plaintext + key
Beaufort subtracts the plaintext from the key:
key - plaintext
Variant Beaufort subtracts the key from the plaintext:
plaintext - key
Those last two are easy to mix up. But K - P and P - K are not the same operation.
In standard Beaufort, the key acts like a mirror point. The plaintext is reflected through the key to produce ciphertext. In Variant Beaufort, the operation points the other way.
So the clean distinction is:
| System | Simple description |
|---|---|
| Vigenère | Add the key |
| Beaufort | Key minus text |
| Variant Beaufort | Text minus key |
The Beaufort tool uses the standard reciprocal Beaufort rule:
C = K - P mod 26
That is the version described in this article.
History and origin
The Beaufort cipher is traditionally associated with Sir Francis Beaufort.
Beaufort is better known for the Beaufort wind scale, the system used to describe wind force from observed conditions at sea. That connection gives the cipher a fitting atmosphere: naval discipline, tables, measurement, weather, signals, and practical hand calculation.
But the historical story of the cipher should be handled carefully.
Some classical ciphers have clean legends. Caesar is linked with Julius Caesar. Playfair is tied to nineteenth-century British diplomatic and military use. Hill has a clearly named inventor, Lester S. Hill, and a definite mathematical setting in the twentieth century.
Beaufort is a little less straightforward.
It belongs to the wider family of Vigenère-style polyalphabetic ciphers: systems that use a repeated key to vary the substitution alphabet across the message. Its importance lies less in a dramatic invention story and more in its elegant mechanism.
The historical value of the Beaufort cipher is that it shows another way to use the Vigenère idea. Instead of shifting forward with the key, it reverses the relationship.
That reversal creates a reciprocal cipher.
In practical terms, this meant a sender and receiver could use the same operation for encryption and decryption. For hand ciphers, that kind of procedural simplicity mattered. The fewer distinct rules a human operator had to remember, the less likely they were to make mistakes.
The Beaufort cipher therefore deserves attention not because it changed the course of world history, but because it is a clean and memorable variation on one of classical cryptography's central ideas.
A repeated keyword can do more than shift. It can reflect.
Why Beaufort was useful
The Beaufort cipher is weak by modern standards, but weak does not mean pointless.
In its own classical setting, it had several real advantages.
First, it was stronger than simple monoalphabetic substitution. A Caesar cipher always shifts letters by the same amount. Atbash always reverses the alphabet in the same way. A simple substitution cipher always maps each plaintext letter to the same ciphertext letter.
Beaufort changes the mapping as the key changes. That means the same plaintext letter can produce different ciphertext letters in different positions.
Second, the key could be memorable. A keyword such as:
FORTIFICATION
is much easier for a human to remember than a long random string of letters.
Third, the cipher was reciprocal. The same rule works in both directions. That makes the method easier to teach, remember, and use.
Fourth, Beaufort is mathematically compact. The whole cipher can be expressed as:
C = (K - P) mod 26
That formula captures the full mechanism.
It also gives learners a useful introduction to repeated-key encryption, modular arithmetic, polyalphabetic substitution, reciprocal operations, key alignment, and the difference between similar-looking formulas.
That educational value is still strong today. Beaufort is small enough to understand by hand, but rich enough to teach something real.
Weaknesses and limitations
The Beaufort cipher improves on simple substitution, but it is still not secure.
Its main weakness is the repeated keyword.
If the key is:
FORTIFICATION
then the key length is 13.
That means every 13 letters, the same key position returns. Letter 1 is encrypted with key letter 1. Letter 14 is encrypted with key letter 1 again. Letter 27 is encrypted with key letter 1 again.
The same is true for each key position.
That repetition creates structure. And structure is what cryptanalysis feeds on.
| Weakness | Why it matters |
|---|---|
| Repeated keyword | The same key positions return again and again |
| Periodic structure | The ciphertext can be split into streams by key position |
| Language patterns remain | English letter frequencies are disguised, not destroyed |
| Known plaintext can reveal key fragments | If plaintext and ciphertext are both known, the key can be recovered locally |
| Human-chosen keys are often guessable | Real keywords are rarely random |
| Not authenticated | It provides no protection against tampering |
| Small classical alphabet | Standard Beaufort usually works only on A-Z |
The cipher is therefore educational, not secure.
It should not be used for passwords, API keys, personal data, financial information, private messages, recovery phrases, or anything that genuinely needs modern encryption.
That does not make it worthless. It makes it a historical and educational cipher.
Its job today is not to protect secrets. Its job is to teach how older secret-writing systems worked and why they eventually failed.
How Beaufort is broken
The Beaufort cipher can be attacked in a similar broad way to Vigenère. The exact arithmetic differs, but the repeated-key weakness remains.
A practical attacker would usually ask:
Can I find the key length?
If the key length can be guessed, the cipher becomes much easier to analyse.
Suppose the key length is 5. Then the ciphertext can be split into five streams:
| Stream | Ciphertext positions |
|---|---|
| Stream 1 | 1, 6, 11, 16, 21, ... |
| Stream 2 | 2, 7, 12, 17, 22, ... |
| Stream 3 | 3, 8, 13, 18, 23, ... |
| Stream 4 | 4, 9, 14, 19, 24, ... |
| Stream 5 | 5, 10, 15, 20, 25, ... |
Each stream was encrypted using the same key letter. That means each stream has a simpler relationship to the original language.
The attacker can then apply frequency-based reasoning to each stream.
In English, letters are not evenly distributed. E, T, A, O, I, N, S, H, and R occur more often than letters such as Q, X, Z, and J. A polyalphabetic cipher disguises those patterns, but if the key repeats, the patterns can start to reappear when the message is split by key position.
There are two classic ideas here:
| Method | Basic idea |
|---|---|
| Repeated-sequence analysis | Repeated ciphertext fragments may reveal distances related to the key length |
| Index of coincidence | Statistical unevenness can help estimate whether text has been encrypted with a repeated key |
Once the likely key length is known, the attacker can work on each key position separately.
The Beaufort formula is:
C = K - P mod 26
Rearrange it:
K = C + P mod 26
That means known or guessed plaintext can reveal key letters.
For example, suppose an attacker sees:
FVYTGV
and guesses the plaintext is:
ATTACK
Write the plaintext and ciphertext as numbers:
| Plain | A | T | T | A | C | K |
|---|---|---|---|---|---|---|
| P | 0 | 19 | 19 | 0 | 2 | 10 |
| Cipher | F | V | Y | T | G | V |
|---|---|---|---|---|---|---|
| C | 5 | 21 | 24 | 19 | 6 | 21 |
Now use:
K = C + P mod 26
| P | C | Calculation | Key number | Key letter |
|---|---|---|---|---|
| 0 | 5 | 0 + 5 = 5 |
5 | F |
| 19 | 21 | 19 + 21 = 40 ≡ 14 |
14 | O |
| 19 | 24 | 19 + 24 = 43 ≡ 17 |
17 | R |
| 0 | 19 | 0 + 19 = 19 |
19 | T |
| 2 | 6 | 2 + 6 = 8 |
8 | I |
| 10 | 21 | 10 + 21 = 31 ≡ 5 |
5 | F |
The recovered key fragment is:
FORTIF
That is already suggestive. If the full key is FORTIFICATION, the attacker has found the beginning of it.
This is why predictable plaintext is dangerous. Messages often contain repeated or guessable words: greetings, dates, names, ranks, commands, places, signatures, weather terms, and common phrases.
If enough plaintext can be guessed, the key begins to show through. The cipher's elegant formula becomes a cryptanalytic handle.
Related ciphers and comparisons
The Beaufort cipher sits in the middle of a useful family of classical systems.
| Cipher | Relationship to Beaufort |
|---|---|
| Caesar cipher | A simple fixed-shift substitution cipher |
| Atbash cipher | A fixed alphabet reversal |
| Vigenère cipher | A repeated-key polyalphabetic cipher using addition |
| Beaufort cipher | A repeated-key polyalphabetic cipher using key-minus-text |
| Variant Beaufort | A related cipher using text-minus-key |
| One-time pad | Uses a key stream, but requires a truly random non-reused key as long as the message |
The closest comparison is Vigenère.
Vigenère says:
ciphertext = plaintext + key
Beaufort says:
ciphertext = key - plaintext
That small change gives Beaufort its reciprocal nature.
A helpful way to remember the difference is:
| Cipher | Mental image |
|---|---|
| Caesar | Slide the alphabet by a fixed amount |
| Vigenère | Slide the alphabet by a changing keyword |
| Beaufort | Reflect the plaintext through the key |
| Variant Beaufort | Move the plaintext backwards by the key |
This makes Beaufort especially useful for learners. It shows that cryptographic systems can be very close in appearance but meaningfully different in operation.
Changing one sign in a formula can change the whole practical behaviour of a cipher.
Where Beaufort appears today
The Beaufort cipher is not one of the most famous pop-culture ciphers.
Caesar, Atbash, Morse code, binary, A1Z26, and simple symbol substitution are more likely to appear in children's books, puzzle hunts, escape rooms, ARGs, geocaching clues, and visible cipher culture.
That is because they are visually immediate. A Caesar shift can be explained with a wheel. Atbash can be explained by writing the alphabet backwards. Morse code has dots and dashes. Binary has 1s and 0s.
Beaufort is less obvious at a glance. It needs a keyword and a modular subtraction rule. It is more mathematical than visual.
But it still appears in online cipher tools, recreational cryptography, puzzle communities, classroom examples, programming exercises, cryptography history discussions, explanations of Vigenère-like ciphers, and codebreaking practice.
Its modern value is mainly educational. It teaches the reader to look beneath the surface.
Two ciphers may both use a repeated keyword, both produce similar-looking ciphertext, and both belong to the same general family. But the formula underneath can be different.
That is a serious cryptographic lesson. Surface similarity is not structural identity.
A simple Python Beaufort cipher
The Beaufort cipher is a good programming example because the code follows the mathematics very directly.
The script below:
- encrypts using standard Beaufort;
- decrypts using the same function;
- preserves spaces and punctuation;
- preserves uppercase and lowercase style;
- advances the key only when a letter is processed;
- uses the formula
output = key - input mod 26.
Python exampleShow code
ALPHABET_SIZE = 26
def clean_key(key):
"""
Keep only letters from the key and convert them to uppercase.
Beaufort needs at least one usable key letter.
"""
cleaned = ""
for char in key:
if char.isalpha():
cleaned += char.upper()
if cleaned == "":
raise ValueError("The key must contain at least one letter.")
return cleaned
def beaufort_transform(text, key):
"""
Encrypt or decrypt text using the standard Beaufort cipher.
Beaufort is reciprocal, so the same function works both ways.
Formula:
output = (K - X) mod 26
X is the input letter number.
K is the key letter number.
"""
key = clean_key(key)
output = []
key_index = 0
for char in text:
if char.isalpha():
# Preserve the case style of the original character.
if char.isupper():
base = ord("A")
else:
base = ord("a")
# Convert the input letter to a number from 0 to 25.
x = ord(char.upper()) - ord("A")
# Get the current key letter.
key_char = key[key_index % len(key)]
k = ord(key_char) - ord("A")
# Beaufort rule: key minus input, modulo 26.
y = (k - x) % ALPHABET_SIZE
# Convert the result back into a letter.
output.append(chr(base + y))
# Advance the key only after a letter.
key_index += 1
else:
# Preserve spaces, punctuation, digits, and symbols.
output.append(char)
return "".join(output)
# Example
plaintext = "ATTACK AT DAWN"
key = "FORTIFICATION"
ciphertext = beaufort_transform(plaintext, key)
recovered = beaufort_transform(ciphertext, key)
print("Plaintext :", plaintext)
print("Key :", key)
print("Encrypted :", ciphertext)
print("Decrypted :", recovered)
Expected output:
Plaintext : ATTACK AT DAWN
Key : FORTIFICATION
Encrypted : FVYTGV IJ XTMB
Decrypted : ATTACK AT DAWN
The most important line is:
y = (k - x) % ALPHABET_SIZE
That line is the Beaufort cipher.
The variable x is the input letter number. The variable k is the key letter number.
The expression:
(k - x) % 26
is the Python version of:
output = key - input mod 26
When the input is plaintext, the output is ciphertext. When the input is ciphertext, the output is plaintext.
That is why the same function can encrypt and decrypt.
Reading the code like the cipher
The code follows the same rhythm as the cipher itself.
First, it cleans the key:
cleaned += char.upper()
This means a key such as:
Fortification!
becomes:
FORTIFICATION
Then the code loops through the input text one character at a time.
If the character is a letter, it is processed. If the character is not a letter, it is preserved.
So spaces, punctuation, digits, and symbols can remain in the output. This makes the tool easier to use, though it also preserves some visible structure.
The line:
x = ord(char.upper()) - ord("A")
turns a letter into a number.
| Letter | Calculation | Number |
|---|---|---|
| A | ord("A") - ord("A") |
0 |
| B | ord("B") - ord("A") |
1 |
| C | ord("C") - ord("A") |
2 |
| Z | ord("Z") - ord("A") |
25 |
The key letter is handled in the same way:
k = ord(key_char) - ord("A")
Then the Beaufort rule is applied:
y = (k - x) % ALPHABET_SIZE
Finally, the number is turned back into a letter:
output.append(chr(base + y))
The code is deliberately simple. It is not trying to be clever. It is trying to make the cipher visible.
That is the right priority for an educational cryptography tool.
Common questions about the Beaufort cipher
Is the Beaufort cipher secure?
No. The Beaufort cipher is not secure by modern standards. It is a repeated-key classical cipher, which means it contains periodic structure. With enough ciphertext, an attacker can estimate the key length and analyse the message by key position.
It should be used for learning, puzzles, and historical interest only. It should not be used for real private information.
Is Beaufort the same as Vigenère?
No. They are closely related, but they use different formulas.
Vigenère uses:
C = P + K mod 26
Beaufort uses:
C = K - P mod 26
That difference makes Beaufort reciprocal.
Why is Beaufort called reciprocal?
Because the same operation encrypts and decrypts.
If encryption gives:
C = K - P mod 26
then decryption uses:
P = K - C mod 26
The structure is the same: key minus text.
What is the difference between Beaufort and Variant Beaufort?
Standard Beaufort uses:
C = K - P mod 26
Variant Beaufort uses:
C = P - K mod 26
They are related, but they are not the same cipher. The standard Beaufort cipher is reciprocal.
What is a good Beaufort example?
A useful example is:
| Item | Value |
|---|---|
| Plaintext | ATTACK AT DAWN |
| Key | FORTIFICATION |
| Ciphertext | FVYTGV IJ XTMB |
This example is also used in the Beaufort tool.
Does the key advance over spaces?
Usually, no.
In a user-friendly Beaufort tool, the key advances only when a letter is processed. So in:
ATTACK AT DAWN
the space does not consume a key letter. This keeps the key aligned with the actual message letters.
Can Beaufort preserve punctuation and numbers?
Yes, a tool can preserve punctuation and numbers for readability.
For example:
Attack at dawn!
might become:
Fvytgv ij xtmb!
The punctuation remains visible. That is convenient, but it also leaks some structure. Classical ciphertext often removes spaces and punctuation and groups letters into blocks.
Why does modulo 26 matter?
Modulo 26 keeps the result inside the alphabet.
For example:
14 - 19 = -5
But there is no letter numbered -5. So we wrap around the alphabet:
-5 mod 26 = 21
21 = V.
Without modular arithmetic, the cipher would not stay inside A-Z.
Why Beaufort still matters
The Beaufort cipher should not be used to protect anything serious.
Not passwords. Not private messages. Not personal information. Not financial data. Not recovery phrases. Not API keys.
Modern encryption uses carefully analysed algorithms, large keys, randomness, authentication, and resistance to many different kinds of attack. Beaufort has none of that.
But it still earns its place.
It shows how a repeated keyword can change the substitution alphabet as a message progresses. It shows how modular arithmetic turns letters into a working cipher. It shows how closely related ciphers can differ by a single sign. It shows why reciprocal encryption is elegant. It shows why repeated keys are dangerous. It shows why a cipher can be clever and still insecure.
And most importantly, it teaches that cryptography is not just about hiding letters.
It is about transformations. Rules. Inverses. Patterns. Leakage.
The Beaufort cipher is one of the cleanest classical examples of that idea.
Vigenère adds. Variant Beaufort subtracts one way. Beaufort subtracts the other way and becomes a mirror.
That is why the Beaufort cipher still matters.
Not because it is strong. Because it shows how a small mathematical reversal can change the whole shape of a cipher.