Playfair Cipher
A digraph substitution cipher that encrypts pairs of letters using a 5x5 matrix key.
ποΈ Historical Background of the Playfair Cipher
The Playfair Cipher was invented by Charles Wheatstone in 1854 but popularized by Lord Playfair, after whom it is named. It was the first practical digraph substitution cipher, encrypting pairs of letters instead of single letters.
It gained significant use during World War I and II due to its stronger security compared to simple substitution ciphers. The Playfair Cipher makes frequency analysis more difficult by encrypting letter pairs, thus disguising letter frequencies.
π Playfair Cipher Principle
The Playfair Cipher encrypts plaintext by dividing it into pairs of letters (digraphs) and substituting them based on their positions in a 5x5 matrix constructed from a keyword.
The cipher uses a 25-letter matrix formed by the keyword followed by the remaining letters of the alphabet and alphabet 'J' is replaced with 'I'.
Example 5x5 Matrix
keyword = MONARCHY
Rules for encrypting each pair of letters:
- Same row: Replace each letter with the letter to its immediate right (wrap around to the start if needed).
- Same column: Replace each letter with the letter immediately below it (wrap around to the top if needed).
- Rectangle: If letters form a rectangle, replace each with the letter in the same row but in the other letterβs column.
Key Characteristics:
- Digraph Substitution: Encrypts letter pairs rather than single letters, increasing complexity.
- Keyword-based matrix: The encryption depends on the chosen keyword.
- Case-insensitive: Typically converts all to uppercase and omits punctuation.
βοΈ Step-by-Step Guidance to Playfair Cipher
π Playfair Cipher Encryption Example
Step 1: Create the 5x5 Matrix Using the Keyword
Use the keyword LEMON
, remove duplicates, then fill in the rest of the alphabet (combine I/J).
Matrix:
Step 2: Prepare the Plaintext
Plaintext: HELLO
Step 3: Encrypt Each Pair Using the Rules
Pair 1: HE
- H is at row 3, column 2
- E is at row 1, column 2
- Same column β Each letter shifts one step down in the same column.
- H β R (row 3 β row 4, same column 2)
- E β B (row 1 β row 2, same column 2)
- Encrypted pair:
RB
Pair 2: LL (Repeated letters)
- Insert an 'X' between repeated letters β pairs become
L X
andL O
Pair 2 (adjusted): LX
- L at row 1, column 1
- X at row 5, column 3
- Rectangle rule β Each letter is replaced by the letter in the same row but in the other pair letter's column, forming a rectangle swap.
- L β M (row 1, col 3)
- X β V (row 5, col 1)
- Encrypted pair:
MV
Pair 3: LO
- L at row 1, column 1
- O at row 1, column 4
- Same row β Each letter shifts one step to the right in the same row.
- L β E (row 1, col 2)
- O β N (row 1, col 5)
- Encrypted pair:
EN
Final encrypted text: RBMVEN
π Playfair Cipher Decryption
Step 1: Use the Same Matrix and Keyword
The decryption uses the same keyword matrix as encryption.
Step 2: Decrypt Each Pair Using the Reverse Rules
- Same row: Replace each letter with the letter to its immediate left (wrap around to the end if needed).
- Same column: Replace each letter with the letter immediately above it (wrap around to the bottom if needed).
- Rectangle: Each letter is replaced by the letter in the same row but in the other pair letter's column, forming a rectangle swap.
Pair 1: RB
- R is at row 4, column 2
- B is at row 2, column 2
- Same column β Each letter shifts one step down in the same column.
- R β H (row 4 β row 3, same column 2)
- B β E (row 2 β row 1, same column 2)
- Decrypted pair:
RB
Pair 2: MV
- M is at row 1, column 3
- V is at row 5, column 1
- Rectangle rule β Each letter is replaced by the letter in the same row but in the other pair letter's column, forming a rectangle swap.
- M β L (row 1, col 3)
- V β X (row 5, col 3)
- Decrypted pair:
LX
Pair 3: EN
- E at row 1, column 2
- N at row 1, column 5
- Same row β Each letter shifts one step to the right in the same row.
- E β L (row 1, col 1)
- N β O (row 1, col 4)
- Decrypted pair:
LO
Step 3: Remove Added 'X's if Applicable
After decryption, remove any filler 'X's inserted between duplicate letters or at the end, if they donβt make sense.
Ciphertext Pair: RBMVEN - R and B β decrypt to H and E - M and V β decrypt to L and X (remove X if filler) - E and N β decrypt to L and O
πFinal encrypted text: HELLO
Playfair Cipher Quiz
- Replace J with I.
- Break text into pairs. Insert X if needed.
- Same row: Replace each letter with the letter to its immediate right (encrypt) or left (decrypt).
- Same column: Replace each letter with the letter immediately below it (encrypt) or above it (decrypt).
- Rectangle: If letters form a rectangle, replace each with the letter in the same row but in the other letterβs column.
Result:
Score: 0
π Additional Resources
- Playfair Cipher Tutorial - View Resource
- TutorialsPoint- Playfair Cipher in Cryptography - View Resource
- PLayfair - View Resource