Gronsfeld Cipher
Encode and decode the Gronsfeld cipher, a simplified Vigenère cipher that uses a short string of digits as its key. Each digit shifts the matching letter of your message, and the key repeats across the text. Switch between encode and decode and watch the working build live. Everything runs in your browser.
Key digits
Enter the key as a string of digits 0 to 9, such as 31415. Each digit sets how far the matching letter of your message is shifted, and the key repeats across the text. Only the digits are used; any letters, spaces, or punctuation typed into the key are ignored.
Enter text above to see the Gronsfeld result here.
How to use Gronsfeld Cipher
- 1
Choose encode or decode
Pick Encode to turn plaintext into Gronsfeld ciphertext, or Decode to recover the plaintext from ciphertext. The same numeric key is used for both directions.
- 2
Enter the numeric key
Type the key as a string of digits 0 to 9, such as 31415. Each digit sets the shift for the letter it lines up with, and the key repeats across the message. Letters, spaces, and punctuation in the key are ignored.
- 3
Type or paste your text
Enter the message you want to convert. The cipher runs automatically as you type, and the letter-by-letter working updates live below so you can see each shift.
- 4
Read, copy, and share
Read the result, then copy it, download it as a text file, or share a link that reopens the tool with your exact key, direction, and text. Everything stays in your browser.
Understanding the Gronsfeld Cipher
What is the Gronsfeld cipher?
The Gronsfeld cipher is a polyalphabetic substitution cipher that works exactly like the Vigenère cipher but takes its key as a short string of digits instead of a keyword. Each digit from 0 to 9 tells you how far to shift the matching letter of the message, and the digits repeat across the text. Because the same plaintext letter can become several different ciphertext letters depending on its position, the cipher hides the simple letter-frequency pattern that gives a plain Caesar shift away.
The cipher is named after Johann Franz, Count of Gronsfeld, a seventeenth-century diplomat and soldier, and it was described by the scholar Gaspar Schott in his 1665 work on secret writing. Its appeal was practical: a numeric key is easy to remember and easy to send, for example as a date or a memorable number, without having to agree on a secret word in advance. For that reason the Gronsfeld cipher saw real use in correspondence and later in the telegraph era.
How the Gronsfeld cipher works
Number the alphabet from A as 0 to Z as 25. Write the numeric key under the message, repeating it as often as needed so that one digit sits under every letter. To encrypt, add each key digit to the letter above it and wrap around the alphabet with a remainder by 26, so the ciphertext letter is C = (P + K) mod 26. To decrypt you subtract instead, P = (C − K) mod 26, which undoes the shift and returns the original letter.
Only the 26 letters are shifted. Spaces, punctuation, and even digits that appear in the message itself pass straight through and do not consume a key digit, so the key stays lined up with the letters that matter. Letter case is preserved, so an uppercase letter stays uppercase and a lowercase letter stays lowercase. Because every digit is between 0 and 9, each position uses one of only ten possible shifts, which is the defining trait of the Gronsfeld cipher.
Worked example
Encrypt the message HELLO with the numeric key 31415. Repeating the key lines up the digits 3, 1, 4, 1, 5 under the letters H, E, L, L, O. Shifting each letter forward by its digit gives H plus 3 is K, E plus 1 is F, L plus 4 is P, L plus 1 is M, and O plus 5 is T. The ciphertext is KFPMT.
To decrypt KFPMT with the same key 31415, subtract each digit instead. K minus 3 is H, F minus 1 is E, P minus 4 is L, M minus 1 is L, and T minus 5 is O, which spells HELLO again. The encode and decode steps are mirror images of each other, so the only thing the receiver needs is the same numeric key.
Gronsfeld versus Vigenère
The Gronsfeld cipher is best understood as a Vigenère cipher with a restricted key. A Vigenère keyword turns each of its letters into a shift from 0 to 25, using the whole alphabet. A Gronsfeld key only ever uses the shifts 0 through 9, which are the same as the Vigenère keyword letters A through J. So the Gronsfeld key 31415 behaves identically to the Vigenère keyword DBEBF, because D is a shift of 3, B is a shift of 1, E is a shift of 4, and so on.
This restriction is a trade-off. The advantage is convenience: a number is simpler to remember, dictate, or carry than a word, and there is no alphabet-to-shift conversion to do in your head. The cost is strength. Because only ten of the twenty-six possible shifts are ever used at each position, the key space is far smaller than a full Vigenère key of the same length, which makes the Gronsfeld cipher easier to break.
Why use a number as the key?
A numeric key is the whole point of the Gronsfeld cipher. People are good at remembering numbers that already mean something to them, such as a birth date, a street number, or the opening digits of a familiar constant like pi. Two correspondents can agree on such a number quickly and reconstruct it from memory, without writing down a secret word that might be found.
Numbers also travel cleanly. In the age of the telegraph a key made of digits could be transmitted and recorded with less chance of error than a word, and it needed no special code book. That practicality is why the Gronsfeld cipher remained popular for everyday secret writing long after stronger methods existed, and why it still turns up today in puzzles and teaching.
How to break the Gronsfeld cipher
Gronsfeld is a repeating-key cipher, so it falls to the same attack that breaks Vigenère, only more easily. The first step is to find the length of the key. Classic tools for this are the Kasiski examination, which measures the distances between repeated groups of letters, and the index of coincidence, which detects how uneven the letter frequencies are. Once the key length is known, the ciphertext splits into columns that were each shifted by a single digit.
Solving each column is where Gronsfeld is weaker than Vigenère. Each column was shifted by one of only ten possible values, so an attacker can simply try all ten and pick the shift that makes the column read like normal language. With short keys the whole key can even be found by brute force, since there are only ten choices per digit. A Gronsfeld message is therefore only as safe as its key is long, unpredictable, and never reused.
Is the Gronsfeld cipher secure?
No. By modern standards the Gronsfeld cipher offers no real security. Its small per-letter key space and its repeating key make it quick to break with pencil-and-paper methods, and trivial for a computer. It belongs to the history of hand ciphers, where its value was the convenience of a numeric key rather than any serious resistance to analysis.
Today the Gronsfeld cipher is enjoyed for learning and for fun. It is a clear, friendly way to see how a numeric key drives a polyalphabetic shift, and it appears regularly in puzzle hunts, escape rooms, geocaching, and capture-the-flag challenges. For protecting real information you should rely on modern, well-tested algorithms such as AES instead.
Frequently asked questions
What is the Gronsfeld cipher?
How does the Gronsfeld cipher work?
How is Gronsfeld different from the Vigenère cipher?
Can you show a Gronsfeld cipher example?
What key should I use?
How do I decode a Gronsfeld cipher?
Why does the key use numbers instead of letters?
Does the cipher change spaces, digits, and punctuation?
Is a key digit of 0 allowed?
How do you break the Gronsfeld cipher?
Is the Gronsfeld cipher secure?
Is my text uploaded to a server?
Related tools
Keep going with these handy tools