Playfair


Unlike many of the other ciphers covered in this site, the Playfair Cipher uses a unique and puzzle-like method of encryption. It was developed by Sir Charles Wheatstone in 1854, but is the namesake of Lord Playfair, who popularized its use. It takes advantage of a 5 x 5 grid of letters and pairs of letters when encrypting/decrypting. Playfair was used by British forces in the Zulu Wars, World War I, and World War II. It was chosen as the central British cipher to use due to its relative simplicity: It's easy to teach and it only requires paper and pencil. However, in the heat of battle, simple subsitution ciphers and code-words became more commonplace in the trenches.


Encoding Playfair

Playfair messages are rather easy to explain and describe. First, to create a grid, use a word as the key. For our case, we are going to use the keyword "CRYPTO". Begin to build a 5 x 5 grid with the individual letters of the keyword as the first few letters. In a Playfair key grid, every letter only shows up once. Luckily, we don't have any repeated letters in our key, so we can add CRYPTO as is. If we had a keyword with repeated letters, such as "HELLO", our grid would begin with the letters H E L O. After that, finish the grid with the rest of the alphabet, remembering to skip letters that have already been used in the keyword.

You may have noticed that a 5 x 5 grid would only prodcuce 25 spaces for letters, but there are 26 letters in the alphabet. In the Playfair cipher, we essentially combine I and J into one letter. For simplicity, we will be showing this combination as just "I". But remember that it represents both I and J.

From here, the following steps can be taken:

  1. Divide your plaintext into pairs of letters. For demonstration purposes, we will be using the plaintext "PROGRAMMING".

  2. PR OG RA MM IN G
  3. For Playfair to work properly, we cannot have pairs of letters which are the same letter. So for the MM in PROGRAMMING, we divide the two Ms by an X. Convinently, this fills out every space so that we only have pairs of letters. If we still had singular letters, we would simply add an X to complete the pair. Don't worry, the recipient of the message should be able to figure out which Xs are extraneous from context.

  4. PR OG RA MX MI NG
  5. To encrypt the letters:
    • If the two letters are on the same row: Change each letter in the pair to the one immediately to the right of it, wrapping arond if needed. Take for instance, the PR in the row C R Y P T. We take the two immediately to the right of it. So PR becomes TY.
    • If the two letters are on the same column: Change each letter in the pair to the one immediately below it, wrapping around if needed. Take for instance, the RA in the column R A G M V. We take the two immediately below. So RA becomes AG.
    • Otherwise: If the two letters are not on the same column or the same row, then we form a box around the letters, having the letters stand as the corners of the box. To encrypt, we find the letters at the opposing horizontal corner. Take for instance, the TO. That creates a rectangle that surrounds the top two rows. We take the letters on the oopposing horizontal corner. So TO becomes CE.

Completing out the rest of the text, CRYPTOLOGY IS COOL becomes RYPTCEUFHR KQ OFFU.

Decoding Playfair

Much like other ciphers, decryption of an encrypted message is relatively simple as we can simply follow the steps backwards to get the plaintext. However, just follow the encryption step backwards:

  • If the two letters are on the same row: Take the two letters to the left, wrapping if needed
  • If the two letters are on the same column: Take the two letters above, wrapping if needed
  • Otherwise: Form a box with the letters enclosed and find the direct opposite horizontal corner.

Breaking Playfair

Without a computer, the key length of a Playfair cipher can also be determined by an analysis of repeated pairs of letters - similar to Vigenère. Or, theoretically, if one knows the frequency of pairs of letters in the ciphertext language, one can use a form of frequency analysis to possibly break a Playfair cipher. With a computer, a user could do what is called hill climbing as a method of finding the Playfair cipher. This works by having a computer pseudo-evolve a Playfair table. It initially generates a randomized table, and then checks it against the ciphertext; it then incrementally improves the table to create a key that recreates the plaintext or something close to it.

Playfair Table (Keyword: CRYPTO)

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

Playfair Example

Plaintext:  CR YP TO LO GY IS CO OL
Ciphertext: RY PT CE UF HR KQ OF FU

Practice with Playfair

Example 1: Using the CRYPTO Playfair table, encrypt the message: ATTACK THE HILL AFTER DAWN
Example 2: Using a Playfair table with the key "APPLE", encrypt the message: AN APPLE A DAY KEEPS THE DOCTOR AWAY
Example 3: Using the CRYPTO Playfair table, decrypt the message: MOQB FL FBTD BMA IUFYP
Example 4: Using a Playfair table with the key "LONDON", decrypt the message: QMC SPCMQ ILDNQSLGNB ONTO HADZGDRW"
Paragraph: Using a Playfair table with the key "CITY", decrypt the paragraph:

TY ZTQ ALB DFQA RB YTLFP, AE TGZ CLL TPSQA RB YTLFP, AE TGZ CLG TBF RB VTPGRH, TY ZTQ ALB GNB QN NVVKTONLGUU,
TY ZTQ ALB DQUBO UG DLQTDD, YE TGZ CLM MQPBO RB AKYOFEWHTYA, TE TGZ CLG QGTOPH SE MADLC, TY ZTQ ALB QGGZSH RB GIPMLGUU,
TY ZTQ ALB OQPYSN RB OUQD, TY ZTQ ALB VTLAFQ RB EFOQCTQ, XB LIG DWFQAYKCSN DFBRQF ZO, TL NCG KQCKCSN DFBRQF ZO,
TL TLQF TNN EPCSN KDQFIY CQ LBIZGL, TL TLQF TNN EPCSN KDQFIY CLB QCLFQ ZTA
TS ZOUQY, CLD QFQCPE VGZ OP GYQ MDPL ELB QSGQGLI QFQCPE, INCA QRHB QD YAQ HSAPTDQA CZCLPSTYTDP ASZAPELB PK AAQ DFAKF SBTDTWDE,
GPS BSPB PS BRQ FIDK, TL ALB OZQDQMCYDIF EFBQFB QB YRHSIPYOPH SHMFY

Example 1: ERRETF YKB KFQM OKCAT EBYW
Example 2: EI PLLEB P CPW NHHLR UGP GIHUNQ PVPZY
Example 3: LAND OF HOPE AND GLORY
Example 4: THE RIGHT HONOURABLE LORD PLAYFAIR
Paragraph: IT WAS THE BEST OF TIMES, IT WAS THE WORST OF TIMES, IT WAS THE AGE OF WISDOM, IT WAS THE AGE OF FOOLISHNESS,
IT WAS THE EPOCH OF BELIEF, IT WAS THE EPOCH OF INCREDULITY, IT WAS THE SEASON OF LIGHT, IT WAS THE SEASON OF DARKNESS,
IT WAS THE SPRING OF HOPE, IT WAS THE WINTER OF DESPAIR, WE HAD EVERYTHING BEFORE US, WE HAD NOTHING BEFORE US,
WE WERE ALL GOING DIRECT TO HEAVEN, WE WERE ALL GOING DIRECT THE OTHER WAY
IN SHORT, THE PERIOD WAS SO FAR LIKE THE PRESENT PERIOD, THAT SOME OF ITS NOISIEST AUTHORITIES INSISTED ON ITS BEING RECEIVED,
FOR GOOD OR FOR EVIL, IN THE SUPERLATIVE DEGREE OF COMPARISON ONLY
- Tale of Two Cities, Charles Dickens

Python Application of Playfair

This application to come soon