Tool to decrypt/encrypt the Playfair cipher, a cipher method using a grid and a symmetrical decryption process.
PlayFair Cipher - dCode
Tag(s) : Polygrammic Cipher, GRID_CIPHER
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
The PlayFair cipher is a symmetric cipher based on grid polygram substitution.
Playfair encryption uses a grid, which can be generated by a key word.
Example: Crypt DCODE with the grid:
\ | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
1 | A | B | C | D | E |
2 | F | G | H | I | J |
3 | K | L | M | N | O |
4 | P | Q | R | S | T |
5 | U | W | X | Y | Z |
Split the text into bigrams of 2 letters (complete with a letter if the message is of odd length).
Apply the following rules depending on the position of the letters in the grid:
— if the 2 letters are identical (or if there is only one remaining) insert another letter (for example a X or a Q) after the first letter and cipher the new bigram thus formed
Example: AABCD becomes AXABCD
— if the 2 letters are on the same row, replace them by the ones on their right (loop to the left if the edge of the grid is reached),
Example: C and D are coded DE
— if the 2 letters are on the same column, replace them by the ones directly under (loop to the top if the bottom of the grid is reached),
Example: A and F are coded FK
— else, replace the letters by the ones forming a rectangle with the original pair. The coded bigram begins with the letter on the same row as the first letter to cipher.
Example: AG is crypted BF, FB is crypted GA
Playfair decryption requires a grid, which can be generated by a key word.
Example: Decrypt DCODE with the grid:
\ | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
1 | A | B | C | D | E |
2 | F | G | H | I | J |
3 | K | L | M | N | O |
4 | P | Q | R | S | T |
5 | U | W | X | Y | Z |
Split the text into pairs of letters (bigrams) and apply the following rules according to the letters positions in the grid:
— if the 2 letters are on the same row, replace them by the ones on their left (loop to the right if the edge of the grid is reached),
Example: DE is decrypted CD.
— if the 2 letters are on the same column, replace them by the ones directly above (loop to the bottom if the top of the grid is reached),
Example: FK is decrypted AF.
— else, replace the letters by the ones forming a rectangle with the original pair. Beginning with the letter on the same row as the first letter to crypt.
Example: BF is decrypted AG, GA is decrypted FB
The ciphered message has an even number of letters.
The message may have 25 distinct letters at most (the number of letters in the grid)
It is impossible to find a bigram composed of 2 identical letters
It is impossible that a letter is crypted by itself. (Thanks to LeSingeMalicieux)
All references to games and fair play are clues.
PlayFair can be cracked using a known plaintext attack in order to discover a part of the grid.
Several squares can be used for the same decryption of Playfair, in fact, once a square grid of 25 is found, other squares obtained from the previous by rotating rows and / or columns gives the same result.
Multiple variants can be found when encrypting bigrams. When letters are in column or in rows, it is possible to cipher with the on on the right or on the left, or above or below. Again, when the letters are diagonally positioned, it is possible to write letter1-letter2 or letter2-letter1
1854 by Charles Wheatstone, after the name of one of his friends Lord Playfair.
dCode retains ownership of the "PlayFair Cipher" source code. Any algorithm for the "PlayFair Cipher" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "PlayFair Cipher" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "PlayFair Cipher" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "PlayFair Cipher" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source.
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: PlayFair Cipher on dCode.fr [online website], retrieved on 2025-04-15,