Playing Dirty with Playfair Cipher

I’ve always been interested in codes in one form or another.

I was in elementary school when my mother taught me how to use simple ciphers such as Pigpen and Caesar, although the versions I learned were rather unorthodox; the Pigpen was one grid with several dots in each square and the Caesar was mirrored rather than merely shifted to the side. Either way, I found myself fascinated, and many of my old diary entries can be seen as proto-ciphertext written in sparkly pens. As I got older, my attention shifted to more theoretical code-breaking, such as the harrowing tale of Bletchley Park and Alan Turing’s race to untangle Enigma; Turing’s story particularly resonated with me as a young gay woman looking back onto queer history.

Today, as an adult writing a historical novel, I find myself researching every small detail, from the hair product used by my main character to the ciphers used by his radio operative. While the brilliant yet stubborn Violette is entirely fictional, her occupation is highly grounded in historical basis, and I ended up spiraling down a rabbit hole of different cryptographic methods that her real-life counterparts would use in the field. Among those brought up by agents who were in France during the war, one system struck my attention: the ironically-named Playfair cipher.

Strength in Numbers

Playfair is what’s known as a substitution cipher—that is, a way of encrypting text by substituting one letter for another. Pigpen cipher, where each letter is encoded as a different symbol picked from a series of grids, is one such example. Another popular one is Caesar cipher, where the entire alphabet is shifted a number of times to create a new encoding system. That is, I can decide to shift my alphabet to the right three times, making A=C, B=D, and so on, and simply encode my text with those rules.

However, both of these ciphers have one key weakness; they are monographic, meaning that letters are replaced individually. This makes them highly vulnerable to frequency analysis by third parties. The English language has a very predictable letter frequency, with E being the most common letter, followed by T, A, etc. If I notice that a ciphertext message has the letter Q be the most frequently appearing letter and I know the plaintext is in English, I can assume that Q means E and get to work. Moreover, each letter in Caesar cipher is only ever encoded as one other letter; if I figure out that one Q represents E, then I now know that all Q’s represent E. For that reason, most monographic ciphers lost favor over time.

Playfair, on the other hand, is a polygraphic cipher, meaning that instead of encoding individual letters, it encodes groups of letters. Specifically, it uses digraphs, or pairs of characters, in its encryption. This means that depending on where it appears in a sentence, E can become Q, or C, or M, or almost any other letter. For that reason, single-letter frequency analysis is all but impossible; instead, the person trying to analyze the cipher would need to analyze digraph frequency. This is difficult to do by a single person, since the English language contains 676 possible digraphs. Even in Playfair, where that number is reduced (and we’ll get to why further down!), that’s still some 600 potential letter pairs compared to only 26 letters. By the time an enemy spy were to crack my message, it would have been safely sent and put to use already!

Elementary, My Dear Granville

Amusingly enough, the man for whom Playfair is named and the man who invented it are not the same person. The system was thought up by physicist Charles Wheatstone in 1854, for use in encoding telegraph transmissions. Unfortunately for Wheatstone, the Foreign Office thought his cipher too complicated. According to his close friend, fellow scientist Lyon Playfair, the two proposed teaching a group of schoolchildren the cipher to prove that they could easily learn it; the under secretary at the Office allegedly replied, “That is very possible, but you could never teach it to attachés!” with Playfair tongue-in-cheek calling his comment, “complimentary to our diplomatic service”(Reid 159).

Desperate to promote his friend’s brilliant cipher, Playfair would soon find the perfect opportunity when Lord Granville invited him to a cabinet dinner one January night. Although one day he would be known as a Member of Parliament and eventually the first Baron Playfair of St. Andrew, for now he was merely a chemist who had many influential friends. Playfair was only asked to “make an even number” when Lord Granville discovered he and his guests would number thirteen, and he knew fully well that Lord Palmerston, another guest in attendance, “would never dine with the fatal number”(158).

While dining, Playfair passionately explained to Lord Palmerston Wheatstone’s brand-new cipher. He gave a demonstration using the key “PALMERSTON” and advocated for its use in the upcoming Crimean War. Sure enough, the chemist was in Dublin shortly thereafter when both Lord Palmerston and Lord Granville sent him “two short letters in cipher… showing that they had readily mastered” the encryption technique deemed too complicated for diplomatic attachés (159).

Unfortunately, while Playfair likely only meant to hype up his buddy’s hard work, his constant promotion ended up getting his own name attached to the cipher, rather than Wheatstone’s. When the cipher was put to work in the Boer War and both World Wars, it was referred to as “Playfair’s cipher,” after the man who would not shut up about it, rather than its inventor. Interestingly enough, even these origins got muddied over time. SOE wireless operator Yvonne Cormeau (the subject of last month’s blog!) insisted in a later interview that “Sir Edward Playfair thought [the cipher] out,” confusing an unrelated member of the Treasury with Lord Playfair, in an amusing case of double overshadowing; the woman herself preferred double transposition for security reasons, only “sometimes [using] the Playfair one.”

Let’s Get Encoding

With the history out of the way, let’s actually talk about how to use Playfair.

The encryption guide is drawn out as a 5 by 5 grid, with the alphabet written letter by letter in each square. Now, 5 times 5 is only 25, and the English alphabet has 26 letters, so one has to go. Typically, J becomes the redundant letter, being merged with I.

The order of this grid is determined by the encryption key used. The person encrypting the message and their intended recipient agree on a word or phrase ahead of time and make it the first thing written in the grid. The rest of the alphabet, excluding any repeat letters, follows suit.

For example, say I wanted to encrypt the message, “Meeting at nine at the dock, bring dog,” using the key, “HISTORY.” The resulting grid would look something like this:

Now, let’s work on encoding our message. To do so, we’ll first need to split up our text into digraphs. Repeat letters are a no-go in Playfair, so if we accidentally come up with a pair of repeating letters, like “TT,” we’ll need to break them up with a redundant letter, like X or Q. In addition, if we have an odd number of characters, the final letter will also be paired with a redundant one.

Applying those rules, our message becomes:

ME ET IN GA TN IN EA TX TH ED OC KB RI NG DO GQ

Finally, let’s encode our digraphs using our key! The rules are fairly simple:

If the letters appear in the same row, move each letter to the right. If the letter is at the far right, simply jump back to the left. Thus, “TH” becomes “OI.”

If the letters appear in the same column, move each letter down. If the letter is at the bottom, simply jump back up to the top. Thus, “ME” becomes “VM.”

Finally, if the letters appear neither in the same row nor the same column, draw a little imaginary rectangle on the grid with each letter at a corner. From there, move horizontally to the other “corner” across from it to find your letter. Thus, “ET” becomes “GI.”

Once we encrypt each one of our pairs, we can then put it all together to get the resulting ciphertext:

VMGIS MFBSP SMFYB TOIFE CKGCY HPFKH KP

The decryption process is almost exactly like the encryption process, just backwards. Once again, you break up your ciphertext into letter pairs (VM GI SM FB SP SM FY BT OI FE CK GC YH PF KH KP) and, using our shared key word and alphabet grid, shift the letters in the opposite direction of that needed to encrypt them. Those in the same row move left, those in the same column move up, and everyone else gets made into a rectangle and moves to the opposite horizontal corners. Finally, any weird redundant letters that don’t look like they belong, such as that X and Q, are removed to complete the message: MEETING AT NINE AT THE DOCK BRING DOG. Quick, simple, and effective!

Presumably, the person at the other end receiving the message would know about our shared key. If anyone else were to discover that we used “HISTORY” to encrypt our transmissions and that Playfair was our chosen cipher, our secrecy would be toast. However, even without the key, one could theoretically crack a Playfair cipher by hand. If they could guess a piece of plaintext repeated in each message—for example, if I began each transmission with “MESSAGE TO THE RESISTANCE,” they could try to figure out where in the ciphertext it was placed and begin to slowly piece together the alphabet grid from there.

Otherwise, if they had no such crib, a frequency analysis of the digraphs would have to take place. This is feasible, but incredibly time-consuming and ineffective as done by one person; even with only 25 characters and excluding the 25 repeat-letter combinations, 25 times 25 minus 25 still equals 600 potential digraphs. That’s an incredibly slow and painstaking process, and by the time my enemy finally solved my cipher, the meeting at the dock would have been long since done! It’s no surprise, then, that the considerable security for low effort in the field made Playfair a popular choice in the early 20th century combat theater.

Yesterday’s Secret, Today’s Challenge

With the rise of machine learning, Playfair and other classic ciphers soon became obsolete, as while 600 word pairs pose a challenge to a human decoder, it only takes mere seconds for a computer to perform an analysis and crack the code. In modern day, digital ciphers are more commonly seen, although some attempt to mix the two together—for example, by encoding a message in Playfair and then applying various digital algorithms to the ciphertext. While the era of the classical cipher as a practical tool has come to an end, its little history is no less fascinating, from its underdog origins to its widespread warfare applications—and, of course, as a wonderfully simple introduction to the world of crpytography.

Before I go, I’ll leave you with two bits of Playfair ciphertext, also encrypted with the key of “HISTORY:”

HYSQO YOIBS WHSMP XNRAE YSYHA WHBFY PUMRQ MBASM KHYSC L

SYMNH TSXCH IGBCH ZSXCO HQOHP QYMRX OSNPH OYWDY BECZH KCBDF BU

Can you decode them? Let me know how it goes, and I hope to see you again soon!

Works Cited

Christensen, Chris. "Polygraphic Ciphers." Northern Kentucky University, 2006. Accessed 20 July 2022.

Cormeau, Yvonne Beatrice. "Oral History." Interview by Conrad Wood. Imperial War Museums, 9 February 1984, https://www.iwm.org.uk/collections/item/object/80007171.

Ikhwan, Ali and Robbi Rahim. "Cryptography Technique with Modular Multiplication Block Cipher and Playfair Cipher." International Journal of Scientific Research in Science and Technology, vol. 2, no. 6, 2016, pp. 71-78.

Reid, Thomas W. Memoirs and correspondence of Lyon Playfair. Harper & Brothers, 1899.

Simmons, Gustavus J. "Playfair Cipher." Encyclopædia Britannica, https://www.britannica.com/topic/Playfair-cipher. Accessed 20 July 2022.

Previous
Previous

Milk Punch: a Libation for the Vintage Molecular Mixologist

Next
Next

Yvonne Cormeau, Star Wireless Operator of the SOE