T

Text Machine

Powerful text tools, in your browser

Bazeries Cipher

Encode and decode the Bazeries cipher, the two-stage system devised by the French cryptanalyst Étienne Bazeries in which a single secret number does two jobs at once. Its digits cut the message into groups that are each reversed, and the same number spelled out in words keys a substitution square laid beside the plain alphabet. Pick your number, switch between encode and decode, and watch both squares fill while the transposition and substitution play out letter by letter. Everything runs in your browser.

Secret number key

Number

Spelled out, the number keys the right-hand square; its digits set the transposition group sizes. The classic example uses 23.

Live cipher squares

Square 1 — plain alphabet, down the columns

A
F
L
Q
V
B
G
M
R
W
C
H
N
S
X
D
I
O
T
Y
E
K
P
U
Z

Square 2 — keyed by the number, across the rows

T
W
E
N
Y
H
R
A
B
C
D
F
G
I
K
L
M
O
P
Q
S
U
V
X
Z

Square 2 key: TWENTYTHREE

Plaintext
Ciphertext

Enter text above to see the Bazeries cipher result here.

How to use Bazeries Cipher

  1. 1

    Choose encode or decode

    Pick Encode to turn plaintext into Bazeries ciphertext, or Decode to turn ciphertext back into plaintext. The same secret number is used in both directions.

  2. 2

    Enter the secret number

    Type a whole number from 1 to 999999. The tool spells it out to key the right-hand square and uses its digits to size the transposition groups. The two live squares show exactly how your number arranges the alphabet.

  3. 3

    Type or paste your text

    Enter your message or your ciphertext. The cipher runs automatically, reversing each number-sized group and substituting between the two squares, with a stage-by-stage view of the working.

  4. 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 number, direction, and text. Everything stays in your browser.

Understanding the Bazeries cipher

What is the Bazeries cipher?

The Bazeries cipher is a two-stage pencil-and-paper cipher named after Étienne Bazeries, the celebrated French army cryptanalyst of the late nineteenth century. What makes it elegant is that a single secret number controls the whole system. The same number is used in two different ways: read as a sequence of digits it drives a transposition, and spelled out as a word it keys a substitution. Combining a transposition with a substitution like this is what cryptographers call a product cipher, and it makes the Bazeries cipher noticeably stronger than either step would be alone.

Both stages work on a 25-letter alphabet in which I and J share a cell, the same convention used by the Polybius square and the Playfair cipher. The encoder first reverses small groups of letters, then replaces each letter using two squares set side by side. Because the two squares are built in deliberately different ways, the substitution is not a simple shift but a genuine mixing of the alphabet. The result hides both the order of the letters and their identity, which is exactly the combination Bazeries was after.

How the Bazeries cipher works

Two 5x5 squares sit next to each other. Square 1 holds the plain alphabet, but written downward along the columns, so reading its rows gives A, F, L, Q, V on the first line, then B, G, M, R, W, and so on. Square 2 is the keyed square: the secret number is spelled out in words, its repeated letters are struck out, and the leftover alphabet is appended, all written across the rows in the normal left-to-right reading order. With the number 23 the keyword is TWENTYTHREE, which trims to TWENYHR, so square 2 reads TWENY on its first row, then HRABC, and the rest of the alphabet follows.

Enciphering happens in two passes. First the transposition: the plaintext is cut into consecutive groups whose lengths are the digits of the number taken in turn and repeated, and each group is written out backwards. With the key 23 the message is split two letters, three letters, two, three, and so on, and every little group is reversed. Second the substitution: each letter of that transposed text is located in square 1, and the letter occupying the very same cell of square 2 is written down in its place. Decoding simply runs the machine backwards, undoing the substitution from square 2 to square 1 and then reversing the same groups a second time to restore their original order.

Worked example

Take the word DCODE with the key 23. The digits 2 and 3 split it into DC and ODE, and reversing each group gives CD and EDO, so the transposed text is CDEDO. Now substitute. In square 1 the letter C sits in the cell that, in square 2, holds D; likewise D maps to L, E maps to S, the second D again to L, and O maps to O. Reading those off gives the ciphertext DLSLO. This DCODE to DLSLO result is the standard reference vector for the Bazeries cipher, so you can use it to check any implementation, including this one.

A longer message shows the mixing better. Enciphering WEHAVETAKENTHEBRIDGE with the same key 23 produces SCYTFPSSUTPGHSFMBSRL. Notice that the two copies of the letter pattern in the plaintext do not line up neatly in the ciphertext, because the transposition has shuffled the letters before the substitution ever sees them. To reverse it, set the tool to Decode, type the same number 23, paste SCYTFPSSUTPGHSFMBSRL, and the original WEHAVETAKENTHEBRIDGE returns. The same number is the only thing the two correspondents need to share.

The number key: one secret, two jobs

The clever heart of the Bazeries cipher is that one number carries the entire key. Spelled out as English words and stripped of repeats, it becomes the keyword that scrambles square 2, so the substitution alphabet changes completely when the number changes. Read instead as a string of digits, the very same number sets the rhythm of the transposition: a key of 23 reverses groups of two and three, while a key of 451 would reverse groups of four, five, and one. A single short number is therefore easy to remember yet sets up two independent mechanisms.

This tool accepts any whole number from 1 to 999999. Type it once and you will see square 2 rebuild itself around the spelled-out keyword, the key letters tinted so you can watch the mixing, while the transposition groups in the working below resize to match the digits. Because the number alone determines everything, it is all that travels inside the share link, never the plaintext itself. A zero among the digits is treated as a full group of ten so the grouping always moves forward, and leading zeros are ignored because the key is simply the number.

Étienne Bazeries, the cryptanalyst

Étienne Bazeries spent decades in and around the French military cipher bureau and earned a reputation as one of the great codebreakers of his age. He is best remembered for solving the Great Cipher of Louis XIV, a nomenclator that had resisted analysis for two centuries, and for his sharp public criticism of the cipher devices of his day. He delighted in showing that systems thought to be unbreakable were not, and he proposed his own cipher both as a teaching example and as a challenge to the cryptographers he sparred with.

It is worth separating two things that share his name. The Bazeries cipher on this page is the pencil-and-paper transposition-and-substitution system driven by a number. The Bazeries cylinder is a different invention, a set of lettered wheels in the family of the Jefferson disk and the later American M-94 device. Both grew out of the same restless mind, but they are mechanically unrelated. Here we focus on the cipher, the one you can work entirely with two squares, a number, and a pencil.

How strong is the Bazeries cipher?

By the standards of its own era the Bazeries cipher was a respectable hand system, precisely because it layers two different ideas. The transposition step moves letters around so that frequency analysis cannot simply read the substitution alphabet off the ciphertext, while the substitution step disguises the identity of each letter so that anagramming alone cannot recover the words. Breaking one stage at a time is much harder when the other stage has already blurred the evidence the analyst would rely on.

Against modern methods, though, it offers no real security. The keyspace is tiny: a short number gives only a handful of possibilities, and even a six-digit number is trivial for a computer to search exhaustively. Once the number is guessed, both stages unwind instantly. The transposition is also self-inverse for a fixed key and the substitution is a fixed monoalphabetic mapping, so the structure gives a determined cryptanalyst several footholds. It is a fascinating historical product cipher, not a tool for protecting anything that matters today.

Is the Bazeries cipher secure?

No. Treat the Bazeries cipher as a piece of cryptographic history and a puzzle, not as protection for sensitive information. Its small key and its neat, reversible structure mean that anyone with a computer, and often anyone with patience and a pencil, can recover the message. It shines as a way to learn how transposition and substitution complement each other, and it is a favourite in puzzle hunts, escape rooms, and capture-the-flag challenges for exactly that reason.

Use this tool to explore how Bazeries combined two simple steps into something cleverer than either, to build and solve puzzles, and to check your work against the standard DCODE to DLSLO vector. For real confidentiality, rely on modern, well-tested algorithms such as AES. Everything here runs locally in your browser, so you can experiment as much as you like without anything you type ever leaving your device.

Frequently asked questions

What is the Bazeries cipher?
The Bazeries cipher is a two-stage cipher created by the French cryptanalyst Étienne Bazeries. A single secret number drives both stages: its digits set a transposition that reverses small groups of letters, and the same number spelled out in words keys a substitution between two 5x5 squares. Combining a transposition with a substitution makes it a product cipher.
How does the number key work?
The number is used in two ways at once. Spelled out as English words and stripped of repeated letters, it becomes the keyword for the second square, so the substitution alphabet depends on it. Read as a string of digits, it sets the lengths of the transposition groups that are then reversed. A key of 23 means groups of two and three and a keyword of TWENTYTHREE.
Why are the two squares built differently?
Square 1 is the plain alphabet written downward along the columns, while square 2 is the keyed alphabet written across the rows. This deliberate difference in fill direction is part of the classic definition and is what makes the substitution a real mixing of the alphabet rather than a simple shift. It is also exactly what reproduces the standard DCODE to DLSLO test vector.
Can you show a Bazeries cipher example?
With the key 23, the word DCODE splits into DC and ODE, each group reverses to give CDEDO, and substituting between the squares yields the ciphertext DLSLO. Decoding DLSLO with the same number 23 returns DCODE. A longer example: WEHAVETAKENTHEBRIDGE enciphers to SCYTFPSSUTPGHSFMBSRL.
How do I decode a Bazeries cipher?
Switch the tool to Decode, enter the same number the message was enciphered with, and paste the ciphertext. The tool first undoes the substitution from square 2 back to square 1, then reverses the same number-sized groups a second time to restore the original letter order, rebuilding the plaintext.
What happens to J and to spaces and punctuation?
The Bazeries cipher works on a 25-letter alphabet in which I and J share a cell, so every J is treated as an I. When you encipher, letters are folded to a single case and anything that is not a letter, including spaces, digits, and punctuation, is dropped. That is why the decoded text comes back as continuous letters with no spaces.
Is the Bazeries cipher the same as the Bazeries cylinder?
No. They share an inventor but are mechanically unrelated. The Bazeries cipher is the pencil-and-paper transposition-and-substitution system driven by a number, which is what this tool implements. The Bazeries cylinder is a wheel cipher in the family of the Jefferson disk and the American M-94, using rotating lettered disks instead of squares.
Who was Étienne Bazeries?
Étienne Bazeries was a French military cryptanalyst active around the turn of the twentieth century, famous for solving the Great Cipher of Louis XIV that had gone unread for some two hundred years. He was an outspoken critic of contemporary cipher machines and devised his own cipher partly as a demonstration and a challenge to his peers.
Why reverse groups instead of using a fixed block size?
Letting the digits of the number set the group lengths ties the transposition to the same secret that keys the substitution, so one short number controls everything. The varying group sizes also break up the text more irregularly than a single fixed block would, which helps disguise repeated patterns before the substitution stage is applied.
Is the Bazeries cipher secure?
No. Although layering a transposition and a substitution made it a respectable hand cipher in its day, the keyspace is tiny and a computer can try every number in an instant. Once the number is found, both stages unwind immediately. Treat it as history and as a puzzle, and use a modern algorithm such as AES for real security.
What numbers can I use as the key?
Any whole number from 1 to 999999. The tool spells the number out to build the keyed square and uses its digits for the transposition. A zero among the digits is treated as a group of ten so the grouping always advances, and leading zeros are ignored because the key is simply the value of the number.
Is my text uploaded to a server?
No. All enciphering and deciphering happen entirely in your browser, so your text and your number are never uploaded, logged, or stored. Even a share link keeps your data in the part of the URL after the hash, which browsers never send to a server, so it stays private until you choose to share it.

Related tools

Keep going with these handy tools

Polybius Square

Nihilist Cipher

Caesar Cipher

Vigenère Cipher

Atbash Cipher

Rail Fence Cipher