T

Text Machine

Powerful text tools, in your browser

Two-Square Cipher

Encode and decode the Two-Square cipher, also called double Playfair — a digraph cipher that enciphers letters in pairs across two keyword-mixed 5×5 squares. It is simpler than the Four-Square yet stronger than Playfair, with a vertical or horizontal layout and a reciprocal design where decoding is the very same operation as encoding. Set both keywords, follow the live grid and the pair-by-pair breakdown, and copy, download, or share the result. Everything runs in your browser.

Keywords

Keyword 1 (top / left)

Keyword 2 (bottom / right)

25-letter alphabet: Q is removed from the squares and the text, so J keeps its own cell. The two squares are stacked, and same-column pairs pass through unchanged.

Plain text
Cipher text

Enter text above to see the result here.

Two-square grid

Each plaintext pair is found across the two keyword squares, and the opposite corners of the rectangle it forms are the cipher pair. Keyword cells are highlighted.

Square 1 (top / left)

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

Square 2 (bottom / right)

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

How to use Two-Square Cipher

  1. 1

    Choose encode or decode, an alphabet, and a layout

    Because the Two-Square is reciprocal, Encode and Decode run the same steps; the choice only sets the output spacing. Pick the I/J-merged alphabet or drop-Q, and the vertical or horizontal layout.

  2. 2

    Enter the two keywords

    Type a keyword for the first square and another for the second square. Both sides must share both keywords. Leave one or both blank to use a plain square in its place.

  3. 3

    Type or paste your text

    Enter your message and it is converted as you type. The steps panel shows each plaintext pair over the cipher pair it becomes, with transparencies drawn muted.

  4. 4

    Read the two-square grid

    Open the grid to see the two keyword squares, stacked or side by side to match the layout, with the keyword cells highlighted so you can trace any pair by eye.

  5. 5

    Copy, download, or share

    Copy the result, download it as a text file, or share a link that reopens the tool with your exact text, keywords, alphabet, and layout ready to go.

Understanding the Two-Square Cipher

What is the Two-Square cipher?

The Two-Square cipher, often called double Playfair, is a hand cipher that enciphers letters two at a time using two keyword-mixed 5×5 squares. It sits squarely between Playfair and the Four-Square: Playfair uses one square, the Four-Square uses four, and the Two-Square uses two. It is usually credited to the French cryptographer Félix Delastelle, the same mind behind the Bifid and Four-Square ciphers, and it offers more key material than Playfair while staying easy to work by hand.

Because it works on pairs of letters — digraphs — the Two-Square is a polygraphic substitution cipher. Enciphering pairs flattens the single-letter frequencies that make simple substitution ciphers fall in minutes, and two independent keywords roughly double the key material compared with Playfair. Its one notable quirk is that some pairs are emitted unchanged, a weakness explored below, but as a learnable, elegant cipher it is a favourite in puzzles and capture-the-flag challenges.

How the Two-Square cipher works

Build two 5×5 squares, each holding a keyword-mixed alphabet — the keyword's distinct letters first, in order and without repeats, then the rest of the alphabet. Because 26 letters must fit in 25 cells, one letter is folded, classically by merging I and J into a single cell.

To encipher a pair, locate the first letter in the first square and the second letter in the second square. The two letters mark out a rectangle spanning the squares; the cipher pair is read from the two opposite corners, each staying within its own square. Decoding needs no separate procedure: the Two-Square is reciprocal, so running the exact same steps on the cipher pair returns the original plaintext pair. That self-inverse property is one of the cipher's most charming features.

Vertical and horizontal layouts

The two squares can be arranged in two ways. In the vertical layout they are stacked, one above the other: the first letter of each pair is found in the top square, the second in the bottom square, and the cipher letters share the same rows but swap columns. In the horizontal layout the squares sit side by side: the first letter is found in the left square and the second in the right, and the cipher letters share columns but swap rows.

The two layouts produce different ciphertext from the same keywords, so they are effectively distinct settings the sender and receiver must agree on. With keywords EXAMPLE and KEYWORD and the drop-Q alphabet, the message HELP ME OBI WAN KENOBI encrypts to HE DL XW SD JY AN HO TK DG in the vertical layout, but to XG NB ME BP AI RY PG ES HB in the horizontal layout. Pick the layout above and the live grid re-stacks to match.

The two keywords and the alphabet

The Two-Square cipher has two independent secrets: a keyword for each square. Each square is built exactly like a keyed Playfair or Polybius square — unique keyword letters first, then the remaining alphabet — and the live grid below highlights the keyword cells so you can watch the mixing. Both sender and receiver must share both keywords, the same alphabet variant, and the same layout.

You can leave a keyword blank to use a plain alphabetical square in its place. Leaving both blank makes the two squares identical, which turns the cipher into a fixed letter-pair transposition — a handy way to see the geometry before any keyword mixing is layered in. For real use, two strong, different keywords give the most security.

A worked Two-Square example

Take HELP ME OBI WAN KENOBI with keyword 1 EXAMPLE and keyword 2 KEYWORD, using the drop-Q alphabet and the vertical layout. The text splits into the pairs HE, LP, ME, OB, IW, AN, KE, NO, BI. For HE, H is in the top square and E in the bottom square; because they share a column, the pair passes straight through unchanged as HE — a transparency.

For LP, L is in the top square and P in the bottom square in different columns, so the rectangle's other corners give D in the top square and L in the bottom square: LP becomes DL. Carrying on, the whole message enciphers to HE DL XW SD JY AN HO TK DG. Notice that HE and AN reappear unchanged. Because the cipher is reciprocal, decoding with the same keywords, alphabet, and layout runs the very same steps and recovers HELPMEOBIWANKENOBI.

Transparencies: the Two-Square's weakness

The Two-Square has a famous flaw: whenever the two letters of a pair already share the swapped coordinate — the same column in the vertical layout, or the same row in the horizontal layout — the cipher pair is identical to the plaintext pair. These give-away pairs are called transparencies, and on average about one digraph in five comes out unchanged.

Transparencies leak plaintext straight into the ciphertext and gave cryptanalysts a foothold, which is why the Two-Square was eventually considered weaker than alternatives without this property. The breakdown panel draws transparencies in a muted style so you can see exactly how often they occur for your text and keywords — a vivid illustration of why even a clever hand cipher can betray its message.

Two-Square versus Playfair and Four-Square, and security

The Two-Square is a middle ground in Delastelle's family of square ciphers. It improves on Playfair by using two keywords instead of one and by never needing to split doubled letters — because the two halves of a pair come from different squares, a pair like LL or EE enciphers cleanly. The Four-Square goes further with four squares and no transparencies, at the cost of more setup; the Two-Square keeps things lighter but pays for it with the transparency weakness.

By modern standards the Two-Square is still a classical cipher and not secure against a computer. Like all digraph substitution ciphers it preserves letter-pair frequencies, and its transparencies make it especially vulnerable, so with enough text it yields to digraph-frequency analysis and known-plaintext attacks. Its value today is educational. For protecting real information, always use a modern, peer-reviewed algorithm such as AES, and keep the Two-Square for history, puzzles, and capture-the-flag challenges.

Frequently asked questions

What is the Two-Square cipher?
The Two-Square cipher, also known as double Playfair, is a digraph (letter-pair) substitution cipher that uses two keyword-mixed 5×5 squares. It sits between Playfair, which uses one square, and the Four-Square, which uses four. Letters are enciphered two at a time, and two independent keywords give it more key material than Playfair while keeping it easy to work by hand.
How does the Two-Square cipher work?
Build two keyword-mixed 5×5 squares. To encipher a pair, find the first letter in the first square and the second letter in the second square; the two letters form a rectangle, and the cipher pair is read from the opposite corners, each staying in its own square. Decoding runs the very same steps, because the Two-Square is reciprocal — applying it twice returns the original text.
What is the difference between the vertical and horizontal layouts?
In the vertical layout the two squares are stacked, the first letter of each pair is found in the top square and the second in the bottom, and the cipher letters swap columns. In the horizontal layout the squares sit side by side, the first letter is in the left square and the second in the right, and the cipher letters swap rows. The same keywords give different ciphertext in each layout, so both sides must agree on it.
Why is the Two-Square called double Playfair?
Because it is built from two Playfair-style keyed squares and enciphers digraphs much as Playfair does, the Two-Square is widely nicknamed double Playfair. It should not be confused with the unrelated WWII field cipher sometimes also called double Playfair; here the name simply reflects its two keyword squares and its close kinship with the original Playfair cipher.
Can you show a worked Two-Square example?
With keyword 1 EXAMPLE, keyword 2 KEYWORD, the drop-Q alphabet, and the vertical layout, HELP ME OBI WAN KENOBI splits into HE, LP, ME, OB, IW, AN, KE, NO, BI and enciphers to HE DL XW SD JY AN HO TK DG. HE and AN share a column, so they pass through unchanged as transparencies, while LP becomes DL and the rest follow the rectangle rule.
What are transparencies in the Two-Square cipher?
A transparency is a digraph that enciphers to itself. It happens whenever the two letters already share the coordinate that the cipher would swap — the same column in the vertical layout, or the same row in the horizontal layout. About one digraph in five is a transparency, which leaks plaintext into the ciphertext and is the Two-Square's main weakness. The breakdown panel shows them in a muted style.
How do you decode a Two-Square cipher?
Because the cipher is reciprocal, decoding is exactly the same as encoding: split the cipher text into pairs and run each pair through the two squares again. In this tool, choose Decode and enter the same two keywords, alphabet variant, and layout used to encode, and it rebuilds the message for you, joined without the encoding spaces.
How is the Two-Square different from the Four-Square cipher?
Both are digraph ciphers from Delastelle's family. The Two-Square uses two keyword squares and is reciprocal but suffers from transparencies, where some pairs encipher to themselves. The Four-Square uses four squares — two plain and two keyed — has no transparencies, and is a little stronger, but it needs more setup. The Two-Square trades some strength for a lighter, self-inverse design.
What is the difference between I/J merged and drop-Q?
Twenty-six letters do not fit in twenty-five cells, so one must give way. The classic option merges I and J into one cell, so a J is enciphered as I and a decoded J reads back as I. The alternative removes Q from the squares and the text, keeping I and J distinct. Both sides must use the same variant or the cipher will not decode correctly.
What happens to spaces, numbers, and punctuation?
Only A–Z letters exist on the squares, so spaces, digits, and punctuation are stripped before enciphering and do not reappear when you decode. If the message has an odd number of letters, a filler (X, or Z when the last letter is itself X) is added so it can be split into whole pairs, so a decoded message may end in an extra letter. This loss of formatting is inherent to the cipher.
Do I have to use a keyword in both squares?
No. You can leave either keyword blank to use a plain alphabetical square in its place, and leaving both blank makes the two squares identical — which turns the cipher into a fixed letter-pair transposition, a useful way to see the geometry before keyword mixing. For real use, two strong, different keywords give the most security, and both must be shared with the recipient.
Is my text uploaded to a server?
No. All encoding and decoding happens entirely in your browser, so your text is never uploaded, logged, or stored. Even a share link keeps your text and keywords in the part of the URL after the hash, which browsers never send to a server, so your message stays private until you choose to share the link.

Related tools

Keep going with these handy tools

Four-Square Cipher

Playfair Cipher

Bifid Cipher

Trifid Cipher

Hill Cipher

Caesar Cipher