Skip to content
Also from us: TypologyOnline.com · Free personality tests

Playfair Cipher: When Letters Started Moving in Pairs

How a 5×5 keyword square turned simple substitution into one of classical cryptography's most elegant hand ciphers.

Try the Playfair Cipher tool
Illustration of a Playfair cipher 5 by 5 keyword square encrypting letter pairs
The Playfair cipher encrypts letters in pairs using row, column, and rectangle rules inside a 5×5 keyword square.

Most beginner ciphers work one letter at a time. Caesar shifts each letter. Atbash mirrors each letter. A1Z26 replaces each letter with a number. Affine sends each letter through a formula. The Playfair cipher does something more interesting: it encrypts pairs of letters.

That small change gives the cipher a different character. Instead of treating a message as a string of isolated symbols, Playfair reads it in digraphs: two-letter blocks such as HI, DE, TH, GO, and LD. The cipher then uses a 5×5 keyword square to decide how each pair changes. A single plaintext letter does not always become the same ciphertext letter; each letter is transformed in relation to its partner.

The pair matters. The square matters. The position matters. That is the charm of Playfair. It is not modern encryption, and it is not safe for private messages, passwords, API keys, financial information, or anything serious. But as a classical teaching cipher, it is one of the best. It introduces digraph substitution, key squares, filler letters, I/J merging, rectangle rules, and the idea that a cipher can operate on blocks rather than isolated characters.

Caesar shifts letters. Vigenère changes alphabets. Hill uses matrices. Playfair makes letters cooperate.

Playfair cipher at a glance

Feature Playfair Cipher
Type Digraph / polygraphic substitution cipher
Main idea Encrypt pairs of letters using a 5×5 keyword square
Key Keyword or key phrase used to build the square
Standard square size 5×5
Alphabet handling Usually combines I and J into one cell
Filler letter Often X
Plaintext unit Digraphs: two-letter pairs
Main rules Same row, same column, rectangle
Example key PLAYFAIR EXAMPLE
Example plaintext HIDETHEGOLDINTHETREESTUMP
Prepared plaintext HIDETHEGOLDINTHETREXESTUMP
Example ciphertext BMODZBXDNABEKUDMUIXMMOUVIF
Security Educational only; weak by modern standards
Best use Learning digraph substitution, key squares, and classical codebreaking

The Playfair cipher is one of the best-known digraph substitution ciphers. It was invented in 1854 by Sir Charles Wheatstone and promoted by Lyon Playfair, whose name became attached to it. In one sentence: Playfair encrypts letter pairs using positions inside a 5×5 keyword square.

What is the Playfair cipher?

The Playfair cipher is a polygraphic substitution cipher. That means it encrypts groups of letters rather than single letters. In Playfair, the group size is two.

These two-letter groups are called:

digraphs
bigrams
letter pairs

For example, the message:

HIDE THE GOLD

can be prepared as:

HI DE TH EG OL D...

Each pair is then encrypted using a 5×5 square.

That is very different from a monoalphabetic substitution cipher. In a simple substitution cipher, every plaintext letter has one fixed ciphertext replacement. If E becomes Q, then every E becomes Q throughout the whole message.

Playfair disrupts that. The letter E might encrypt differently depending on the letter paired with it. HE, DE, and EX can all behave differently because the second letter changes the rule.

That makes Playfair harder to break than a simple substitution cipher because ordinary single-letter frequency analysis becomes less useful. The trade-off is simple: Playfair is stronger than beginner substitution, but it still leaks structure.

How Playfair works

The Playfair cipher has three main stages:

  1. Build the 5×5 keyword square.
  2. Prepare the plaintext into letter pairs.
  3. Encrypt each pair using row, column, or rectangle rules.

The square is the heart of the cipher.

A standard English alphabet has 26 letters, but a 5×5 square has only:

5 × 5 = 25

cells.

So one letter has to be removed or merged. The usual convention is that I and J share one cell. That means J is usually converted to I, and the square contains I/J as one combined position.

The Playfair tool uses this convention: I/J share one cell: Yes.

For the keyword:

PLAYFAIR EXAMPLE

the normalised keyword becomes:

PLAYFAIREXAMPLE

Remove repeated letters while keeping the first occurrence of each letter. That gives the start of the square:

P L A Y F I R E X M

Then fill the remaining unused letters of the alphabet, usually skipping J because I/J share a cell.

The square becomes:

1 2 3 4 5
1 P L A Y F
2 I/J R E X M
3 B C D G H
4 K N O Q S
5 T U V W Z

This is the same key square shown in the Playfair tool for PLAYFAIR EXAMPLE.

Once the square exists, every plaintext digraph is transformed according to where its two letters sit.

There are only three real cases:

Case Rule
Same row Move each letter one step to the right
Same column Move each letter one step down
Rectangle Each letter takes the column of the other letter
Repeated pair letters Insert a filler letter before encryption

That is the whole mechanism: simple enough to use by hand, rich enough to teach something real.

Key and rules

The Playfair cipher key is a word or phrase used to build the 5×5 square.

For example:

PLAYFAIR EXAMPLE

The main rules are:

Rule Explanation
Remove duplicate key letters The first occurrence is kept; later repeats are skipped
Fill the square with unused alphabet letters After the keyword, add the remaining letters in order
Merge I and J The 5×5 square has 25 cells, so I/J usually share one cell
Prepare text as digraphs The plaintext is split into two-letter pairs
Split repeated letters in a pair Repeated letters inside one pair are separated with a filler
Add a filler if needed If the final prepared text has odd length, add a filler
Use same-row, same-column, or rectangle rules The rule depends on positions inside the square
Decryption reverses row and column shifts Same row moves left; same column moves up; rectangle rule is symmetric

The filler letter is usually:

X

The filler matters because Playfair cannot encrypt a pair made from the same letter.

For example:

EE

cannot be left as EE. It must be split:

E X E

Then the digraphs become:

EX ES

This is why Playfair can slightly change the visible form of the message. The plaintext the user types is not always exactly the plaintext that gets encrypted. It first becomes prepared plaintext.

That distinction is important. In Playfair, preparation is part of the cipher.

Preparing the plaintext

Suppose the plaintext is:

HIDE THE GOLD IN THE TREE STUMP

First, remove spaces and punctuation:

HIDETHEGOLDINTHETREESTUMP

Then split into pairs:

HI DE TH EG OL DI NT HE TR EE ST UM P

The pair EE is a problem because both letters are the same.

So insert the filler letter X between them:

... TR EX ES ...

Now the prepared text becomes:

HIDETHEGOLDINTHETREXESTUMP

Split into digraphs:

Digraphs HI DE TH EG OL DI NT
Digraphs HE TR EX ES TU MP

This is exactly why the tool warns that prepared plaintext may differ from the raw input, and why decrypting the classic example gives HIDETHEGOLDINTHETREXESTUMP rather than automatically removing the filler X.

That is not a mistake. It is a consequence of how Playfair works. The cipher cannot always know whether an X is a filler or a real letter.

The three Playfair encryption rules

Once the plaintext has been prepared into digraphs, each pair is encrypted using the square.

Using the square from PLAYFAIR EXAMPLE:

1 2 3 4 5
1 P L A Y F
2 I/J R E X M
3 B C D G H
4 K N O Q S
5 T U V W Z

Rule 1: same row

If both letters are in the same row, replace each letter with the letter immediately to its right. If a letter is at the end of the row, wrap around to the start.

Example:

PL

P and L are in the same row.

Letter Position Move right Result
P Row 1, Column 1 Row 1, Column 2 L
L Row 1, Column 2 Row 1, Column 3 A

So:

PL -> LA

Rule 2: same column

If both letters are in the same column, replace each letter with the letter immediately below it. If a letter is at the bottom, wrap around to the top.

Example:

PI

P and I/J are in the same column.

Letter Position Move down Result
P Row 1, Column 1 Row 2, Column 1 I/J
I/J Row 2, Column 1 Row 3, Column 1 B

So:

PI -> IB

Rule 3: rectangle

If the two letters are in different rows and different columns, they form the corners of a rectangle. Each letter is replaced by the letter in the same row but in the other letter's column.

Example:

PR

P is at row 1, column 1. R is at row 2, column 2.

The rectangle corners are:

Column 1 Column 2
Row 1 P L
Row 2 I/J R

P takes R's column, becoming L. R takes P's column, becoming I/J.

So:

PR -> LI

The rectangle rule is the most distinctive part of Playfair. Two letters enter, their positions define a shape, and the shape decides the output.

Worked example: HIDETHEGOLDINTHETREESTUMP

Now encrypt the classic example:

HIDETHEGOLDINTHETREESTUMP

using the keyword:

PLAYFAIR EXAMPLE

The prepared plaintext is:

HIDETHEGOLDINTHETREXESTUMP

Split into digraphs:

1 2 3 4 5 6 7
HI DE TH EG OL DI NT
8 9 10 11 12 13
HE TR EX ES TU MP

Now encrypt each digraph using the square.

The key square

1 2 3 4 5
1 P L A Y F
2 I/J R E X M
3 B C D G H
4 K N O Q S
5 T U V W Z

The digraph encryption

Plain digraph Rule Cipher digraph
HI Rectangle BM
DE Rectangle OD
TH Rectangle ZB
EG Same column XD
OL Rectangle NA
DI Rectangle BE
NT Rectangle KU
HE Rectangle DM
TR Rectangle UI
EX Same row XM
ES Rectangle MO
TU Same row UV
MP Rectangle IF

Put the ciphertext digraphs together:

BM OD ZB XD NA BE KU DM UI XM MO UV IF

Without spaces:

BMODZBXDNABEKUDMUIXMMOUVIF

So:

HIDETHEGOLDINTHETREESTUMP -> BMODZBXDNABEKUDMUIXMMOUVIF

This is the classic example used in the Playfair tool.

The important thing to notice is that Playfair does not merely replace H with B or I with M. It encrypts HI as a unit. The pair becomes BM. The relationship between the two letters matters.

That is the whole cipher.

Decrypting the Playfair cipher

Decryption uses the same square, but the row and column movement reverses.

The rules become:

Cipher pair position Decryption rule
Same row Move each letter one step left
Same column Move each letter one step up
Rectangle Use the same rectangle rule

The rectangle rule is naturally reversible. If two letters form opposite corners of a rectangle, swapping columns once encrypts them, and swapping columns again brings them back.

For example, encryption gave:

PR -> LI

Decrypting LI uses the same rectangle:

LI -> PR

For the classic example:

BMODZBXDNABEKUDMUIXMMOUVIF

decrypting with the same square gives:

HIDETHEGOLDINTHETREXESTUMP

That is the prepared plaintext.

It is very close to the original:

HIDETHEGOLDINTHETREESTUMP

but not identical, because the filler X remains inside:

TREXESTUMP

The original phrase had:

TREESTUMP

The double E was split during preparation:

TREE -> TREXE

The receiver may infer that the X was a filler and mentally remove it, but a computer tool should not always do that automatically. Sometimes X is a real letter.

That is why the tool says decrypting the classic example gives HIDETHEGOLDINTHETREXESTUMP because filler letters are not removed automatically.

This is one of Playfair's small but important practical lessons. Encryption is mechanical. Interpretation is not always mechanical.

History and origin

The Playfair cipher was invented in 1854 by Sir Charles Wheatstone, but it carries the name of Lyon Playfair because Playfair promoted it.

This is a good example of how cipher names can be historically misleading. The inventor was Wheatstone. The promoter was Playfair. The name followed the promoter.

That does not make the name wrong, exactly. It makes it historically layered.

Playfair belonged to a nineteenth-century world of hand ciphers, telegraphy, diplomacy, military communication, paper tables, and practical field methods. It was designed to be usable by humans, not machines.

That matters.

The Playfair cipher is more sophisticated than Caesar or Atbash, but it is still something a person can operate with pencil and paper. The user needs only a keyword, a 5×5 square, a few preparation rules, and three encryption rules.

That combination made it attractive. It was more secure than simple substitution but still practical enough to use without machinery.

Playfair also has a long puzzle-culture afterlife. It appears in recreational cryptography, codebreaking books, classroom examples, and detective fiction. It feels structured, hand-solvable, and just complex enough to feel serious.

Why Playfair was useful

The Playfair cipher was useful because it attacked one of the biggest weaknesses of simple substitution.

A monoalphabetic substitution cipher preserves single-letter frequency patterns. If E is the most common plaintext letter, then its ciphertext substitute often becomes unusually common too. That gives an attacker a way in.

Playfair makes that harder. It encrypts pairs of letters, not single letters.

That means the attacker cannot simply count individual ciphertext letters and map them directly to English letter frequencies. Digraph encryption reduces the survival of raw single-letter frequency information, though it does not eliminate statistical structure completely.

Playfair also had practical advantages:

Advantage Why it mattered
Works by hand No machinery required
Uses a memorable keyword Easier than memorising a whole substitution alphabet
Encrypts letter pairs Stronger than simple single-letter substitution
Has compact rules Same row, same column, rectangle
Hides repeated letters better Double letters are split with fillers
Teaches block thinking Letters are processed in pairs, not alone

That last point is important.

Playfair is not a modern block cipher, but it does introduce the learner to a block-like idea. The unit of encryption is not one symbol. It is a pair.

That is a conceptual step forward.

Weaknesses and limitations

Playfair is clever, but it is not secure by modern standards.

It reduces single-letter frequency leakage, but it does not destroy the structure of language. English has common letter pairs as well as common letters.

Examples include:

TH
HE
IN
ER
AN
RE
ON
AT
EN
ND

Playfair hides these better than simple substitution, but digraph patterns can still be analysed. The row-and-column structure of the square also gives cryptanalysts something to exploit.

The main weaknesses are:

Weakness Why it matters
Digraph frequencies remain Common pairs still leave statistical traces
Key square structure leaks The row/column/rectangle system creates exploitable patterns
I/J ambiguity J is usually merged with I
Filler letters create artefacts Inserted Xs can reveal preparation patterns
Human keywords are guessable People choose meaningful phrases
Same key reused Reuse gives attackers more text to compare
No authentication It does not detect tampering
Manual preparation changes text Decryption may return prepared text, not exactly raw input

There is also a subtle readability issue.

Because filler letters may be inserted, the decrypted message may require human judgement.

For example:

TREXESTUMP

probably means:

TREESTUMP

But the cipher itself cannot always know that.

A good tool should show this honestly rather than silently pretending the issue does not exist.

How the Playfair cipher is broken

The Playfair cipher is usually attacked through patterns in digraphs and through the structure of the square.

A simple Caesar cipher can be brute-forced by trying 26 shifts. Playfair is not that small. The square can be arranged in many ways, and a direct brute force search over all possible squares is not practical by hand.

But Playfair still leaks information.

An attacker can look for:

repeated ciphertext digraphs
common English digraph patterns
likely plaintext words
filler-letter artefacts
row and column relationships
repeated message formats
cribs such as THE, ATTACK, REPORT, MESSAGE, or STOP

A crib is a guessed piece of plaintext.

Suppose an attacker suspects that part of a Playfair ciphertext contains the word:

THE

That word has to appear inside digraphs. Depending on alignment, it might appear as:

TH E...

or:

...T HE

That gives possible plaintext pairs such as TH or HE.

If the attacker can match likely plaintext digraphs to ciphertext digraphs, they begin to learn relationships inside the square. For example, if a plaintext pair and ciphertext pair are related by the rectangle rule, then the four letters must occupy corners of a rectangle in the key square.

If many such relationships are collected, the square begins to take shape.

That is the basic idea.

Playfair is not usually broken by one magic trick. It is broken by accumulating constraints.

The attacker asks:

Which letters may share a row?
Which letters may share a column?
Which pairs look like rectangle substitutions?
Which filler letters suggest repeated plaintext letters?
Which common words fit the ciphertext structure?

Modern computers can automate much of this search. Hill-climbing and simulated annealing methods can test possible key squares and score candidate decryptions according to how English-like they are.

But the principle is still classical. The cipher leaks structure. The attacker uses that structure to reconstruct the square.

Playfair sits in an important place between simple substitution and more mathematical block methods.

Cipher Relationship to Playfair
Caesar cipher Encrypts one letter at a time with a fixed shift
Atbash cipher Encrypts one letter at a time by reversing the alphabet
Monoalphabetic substitution Uses one fixed replacement alphabet
Vigenère cipher Uses changing alphabets selected by a keyword
Playfair cipher Encrypts letter pairs using a 5×5 square
Four-square cipher Also uses digraphs and squares, but with more square structure
Hill cipher Encrypts blocks of letters using matrix multiplication
Polybius square Uses grid coordinates; Playfair also depends on a square layout

The closest conceptual jump is from monoalphabetic substitution to Playfair.

Monoalphabetic substitution says:

one letter in -> one letter out

Playfair says:

two letters in -> two letters out

That change weakens simple frequency analysis and makes the cipher feel more structural.

The comparison with Hill is also useful. Both Playfair and Hill encrypt groups of letters rather than isolated letters. But Playfair uses geometric rules inside a square. Hill uses linear algebra.

Playfair is the hand-cipher version of block thinking. Hill is the mathematical version.

Where Playfair appears today

The Playfair cipher is not as visually immediate as Caesar, Atbash, Morse code, binary, or A1Z26.

Those systems are easier to show quickly in a cartoon, children's puzzle, or background clue.

Playfair needs more setup: a keyword, a 5×5 square, I/J merging, filler rules, digraph preparation, and row, column, and rectangle rules.

That makes it less suitable as a quick on-screen cipher.

But it is still common in recreational cryptography, puzzle hunts, escape rooms, codebreaking challenges, programming exercises, classical cryptography lessons, online cipher tools, and educational CTF-style tasks.

Its modern value is educational.

Playfair teaches that the unit of encryption matters. A cipher does not have to work one letter at a time.

Once you understand that, you are closer to understanding why later cryptography cares so much about blocks, structure, diffusion, and leakage.

A simple Python Playfair cipher

The Playfair cipher is a good programming exercise because it forces you to handle several real cipher details:

  1. key normalisation;
  2. duplicate removal;
  3. I/J merging;
  4. plaintext preparation;
  5. filler insertion;
  6. digraph encryption;
  7. row, column, and rectangle rules;
  8. decryption that returns prepared plaintext.

The code below implements a simple educational Playfair cipher using a 5×5 square, I/J merging, filler letter X, uppercase letters only, and optional grouped output.

It is written for clarity rather than cleverness.

Python exampleShow code
ALPHABET = "ABCDEFGHIKLMNOPQRSTUVWXYZ"  # J is omitted; I/J share a cell


def normalise_letters(text):
    """
    Keep letters only, uppercase them, and merge J into I.
    """
    result = ""

    for char in text.upper():
        if char.isalpha():
            if char == "J":
                result += "I"
            else:
                result += char

    return result


def build_playfair_square(keyword):
    """
    Build a 5x5 Playfair square from a keyword.

    Duplicate letters are removed.
    J is merged into I.
    """
    keyword = normalise_letters(keyword)

    seen = set()
    letters = []

    for char in keyword + ALPHABET:
        if char not in seen:
            seen.add(char)
            letters.append(char)

    square = []
    positions = {}

    for row in range(5):
        square_row = []

        for col in range(5):
            letter = letters[row * 5 + col]
            square_row.append(letter)
            positions[letter] = (row, col)

        square.append(square_row)

    return square, positions


def prepare_plaintext(plaintext, filler="X"):
    """
    Prepare plaintext for Playfair encryption.

    Rules:
    - keep letters only
    - uppercase
    - merge J into I
    - split into digraphs
    - insert filler between repeated letters in a pair
    - add filler at the end if needed
    """
    letters = normalise_letters(plaintext)
    digraphs = []
    i = 0

    while i < len(letters):
        first = letters[i]

        if i + 1 >= len(letters):
            second = filler
            i += 1
        else:
            second = letters[i + 1]

            if first == second:
                # Avoid using the same filler as the repeated letter.
                if first == filler:
                    second = "Q"
                else:
                    second = filler

                i += 1
            else:
                i += 2

        digraphs.append(first + second)

    return digraphs


def encrypt_pair(pair, square, positions):
    """
    Encrypt one Playfair digraph.
    """
    a, b = pair[0], pair[1]

    row_a, col_a = positions[a]
    row_b, col_b = positions[b]

    # Same row: move right.
    if row_a == row_b:
        encrypted_a = square[row_a][(col_a + 1) % 5]
        encrypted_b = square[row_b][(col_b + 1) % 5]

    # Same column: move down.
    elif col_a == col_b:
        encrypted_a = square[(row_a + 1) % 5][col_a]
        encrypted_b = square[(row_b + 1) % 5][col_b]

    # Rectangle: swap columns.
    else:
        encrypted_a = square[row_a][col_b]
        encrypted_b = square[row_b][col_a]

    return encrypted_a + encrypted_b


def decrypt_pair(pair, square, positions):
    """
    Decrypt one Playfair digraph.
    """
    a, b = pair[0], pair[1]

    row_a, col_a = positions[a]
    row_b, col_b = positions[b]

    # Same row: move left.
    if row_a == row_b:
        decrypted_a = square[row_a][(col_a - 1) % 5]
        decrypted_b = square[row_b][(col_b - 1) % 5]

    # Same column: move up.
    elif col_a == col_b:
        decrypted_a = square[(row_a - 1) % 5][col_a]
        decrypted_b = square[(row_b - 1) % 5][col_b]

    # Rectangle: swap columns.
    else:
        decrypted_a = square[row_a][col_b]
        decrypted_b = square[row_b][col_a]

    return decrypted_a + decrypted_b


def playfair_encrypt(plaintext, keyword, filler="X", group_size=5):
    """
    Encrypt plaintext with the Playfair cipher.
    """
    square, positions = build_playfair_square(keyword)
    digraphs = prepare_plaintext(plaintext, filler)

    ciphertext = ""

    for pair in digraphs:
        ciphertext += encrypt_pair(pair, square, positions)

    if group_size:
        groups = []

        for i in range(0, len(ciphertext), group_size):
            groups.append(ciphertext[i:i + group_size])

        return " ".join(groups)

    return ciphertext


def playfair_decrypt(ciphertext, keyword, group_size=0):
    """
    Decrypt ciphertext with the Playfair cipher.

    This returns prepared plaintext.
    It does not automatically remove filler letters.
    """
    square, positions = build_playfair_square(keyword)
    letters = normalise_letters(ciphertext)

    if len(letters) % 2 != 0:
        raise ValueError("Ciphertext must contain an even number of letters.")

    plaintext = ""

    for i in range(0, len(letters), 2):
        pair = letters[i:i + 2]
        plaintext += decrypt_pair(pair, square, positions)

    if group_size:
        groups = []

        for i in range(0, len(plaintext), group_size):
            groups.append(plaintext[i:i + group_size])

        return " ".join(groups)

    return plaintext


def print_square(square):
    """
    Display the Playfair square.
    """
    for row in square:
        print(" ".join(row))


# Example
keyword = "PLAYFAIR EXAMPLE"
plaintext = "HIDETHEGOLDINTHETREESTUMP"

square, positions = build_playfair_square(keyword)

print("Keyword square:")
print_square(square)

encrypted = playfair_encrypt(plaintext, keyword, filler="X", group_size=0)
decrypted = playfair_decrypt(encrypted, keyword)

print()
print("Plaintext :", plaintext)
print("Encrypted :", encrypted)
print("Decrypted :", decrypted)

Expected output:

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

Plaintext : HIDETHEGOLDINTHETREESTUMP
Encrypted : BMODZBXDNABEKUDMUIXMMOUVIF
Decrypted : HIDETHEGOLDINTHETREXESTUMP

The decrypted text contains:

TREXE

rather than:

TREE

because the filler X was inserted between the repeated E letters during preparation. That matches the behaviour described in the Playfair tool.

Reading the code like the cipher

The code starts with the alphabet:

ALPHABET = "ABCDEFGHIKLMNOPQRSTUVWXYZ"

There is no J. That is because I and J share one cell in the standard Playfair square.

The function:

normalise_letters(text)

does three things:

  1. keeps letters only;
  2. converts them to uppercase;
  3. changes J into I.

So:

JIG

becomes:

IIG

This is not a mistake. It is part of the 5×5-square convention.

The function:

build_playfair_square(keyword)

builds the key square. It takes the keyword, removes repeated letters, then fills in the rest of the alphabet.

For:

PLAYFAIR EXAMPLE

the square becomes:

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

The function:

prepare_plaintext(plaintext, filler="X")

turns the message into valid digraphs. It handles repeated letters by inserting a filler.

For example:

TREE

becomes:

TR EX E...

Then another letter follows to complete the next pair. That is how:

TREESTUMP

becomes:

TREXESTUMP

The encryption rule appears inside:

encrypt_pair(pair, square, positions)

This function checks whether the two letters are in the same row, in the same column, or in different rows and columns.

Same row:

encrypted_a = square[row_a][(col_a + 1) % 5]
encrypted_b = square[row_b][(col_b + 1) % 5]

The % 5 makes the row wrap around. If a letter is at the far right, moving right sends it back to the start of the same row.

Same column:

encrypted_a = square[(row_a + 1) % 5][col_a]
encrypted_b = square[(row_b + 1) % 5][col_b]

Again, % 5 creates wrap-around. If a letter is at the bottom, moving down sends it back to the top.

Rectangle:

encrypted_a = square[row_a][col_b]
encrypted_b = square[row_b][col_a]

This is the rectangle rule. Each letter stays in its own row but takes the other letter's column.

That line is the geometric heart of Playfair.

Common questions about the Playfair cipher

Is the Playfair cipher secure?

No. The Playfair cipher is not secure by modern standards.

It is stronger than a simple monoalphabetic substitution cipher because it encrypts pairs of letters, but it still leaks digraph patterns and structural information from the key square.

It should be used for learning, puzzles, and historical interest only.

Why does Playfair combine I and J?

A 5×5 square has 25 cells. The English alphabet has 26 letters.

To fit the alphabet into the square, one letter must be omitted or merged. The usual convention is to combine I and J into one cell.

So J is usually treated as I.

What is a digraph?

A digraph is a pair of letters.

Word Digraphs
HIDE HI DE
GOLD GO LD
ATTACK AT TA CK

Playfair encrypts digraphs instead of individual letters.

Why are filler letters used?

Filler letters are used when a pair contains two of the same letter or when the final message has an odd number of letters.

For example:

TREE

contains EE. Playfair splits this with a filler:

TR EX ES

The filler is often X.

Why does decrypted Playfair text sometimes contain extra Xs?

Because filler letters are inserted before encryption. When the message is decrypted, those filler letters may still appear.

A human reader may remove them when they are obviously fillers, but a program cannot always know whether an X was inserted or whether it was part of the real message.

What are the three Playfair rules?

The three main encryption rules are:

Case Rule
Same row Move both letters right
Same column Move both letters down
Rectangle Swap columns

For decryption:

Case Rule
Same row Move both letters left
Same column Move both letters up
Rectangle Swap columns again

What is a good Playfair example?

A classic example is:

Item Value
Keyword PLAYFAIR EXAMPLE
Plaintext HIDETHEGOLDINTHETREESTUMP
Prepared plaintext HIDETHEGOLDINTHETREXESTUMP
Ciphertext BMODZBXDNABEKUDMUIXMMOUVIF

This is the example used in the Playfair tool.

Why the Playfair cipher still matters

The Playfair cipher should not be used to protect anything serious.

Not passwords. Not private messages. Not personal information. Not financial data. Not API keys. Not recovery phrases.

Modern encryption depends on carefully analysed algorithms, large keyspaces, randomness, authentication, and resistance to many kinds of attack. Playfair has none of that.

But it still earns its place.

It shows that encryption does not have to work one letter at a time. It shows how a keyword can generate a structured square. It shows how geometry can become a cipher rule. It shows why preprocessing matters. It shows why filler letters are awkward. It shows why hiding single-letter frequency is not enough. It shows why patterns survive even when a cipher becomes more clever.

And most importantly, it teaches the shift from single symbols to blocks.

That is a major conceptual step.

Caesar changes letters. Vigenère changes alphabets. Playfair changes pairs.

Once you see that, classical cryptography becomes less like a list of alphabet tricks and more like a sequence of increasingly structured transformations.

That is why the Playfair cipher still matters.

Not because it is strong. Because it teaches the moment when letters stopped standing alone.

Sources and further reading

Try the Playfair Cipher Tool

Want to experiment with the idea in practice? Open the matching tool and try your own text.

Open Playfair Cipher
Signal acquired

A note from the team

We build these tools because we love cryptography, encoding, and making difficult ideas easier to explore. If they've helped you, even a small coffee means the world to the project. Thank you!

Say thanks on Ko-fi

Read next

Matrix Ciphers Hill Cipher: The Day Classical Cryptography Became Mathematical How Lester S. Hill's 1929 matrix cipher moved secret writing beyond alphabet tricks and toward the logic of modern cryptography. Polyalphabetic Vigenère Cipher: When Classical Cryptography Learned to Change Alphabets How a repeating keyword lets classical cryptography rotate among several alphabets instead of relying on one fixed substitution. Cryptanalysis Frequency Analysis: The Statistical Fingerprint That Broke Classical Ciphers How counting letters turned cryptanalysis from educated guesswork into a science, and why weak ciphers still betray themselves through the shape of language.
Back to all articles