Thursday, 11 October 2012

Codes and Ciphers - Playfair

While looking at something else, I was reminded of a cipher invented by Charles Wheatstone called Playfair. It works on pairs of letters, again using a letter grid. Taking the grid we had before:

ZTNL5F
E4KMSY
XR9J3D
C2I8QW
VP7H1B
A0G6OU

We then take a message and split it into two letter groups, so "Send 3 and 4 pence" comes out as "SE ND 3A ND 4P EN CE". If you then look up the letter pairs in the grid, they form the corners of a rectangle. "ND" form a rectangle with "F9" (same row order). "SE" are on the same line, so you select whatever is to the right, in this case "Y4". Similarly, "4P" are in the same column, so we select the next row down, "R0". Continue and we end up with "Y4 F9 XO F9 R0 KZ VX". The letters are wrapped, so "WC" comes out as "C2". Double letters, like "PP" have the second letter as "X", so "PX" comes out as "VR". This makes the decryption look a bit odd, but if you know "X" stands for the duplicate, it's obvious. You're unlikely to get "XX". Have a go at this:

M16ZN8QA4H0X 4ZVM4ZU0YOEJ 4XY3UE
LPUA0XL403MZ A1MZEUF9S6X4 Z44H4X0ZXC
30A6B87K3Y3U M1GE4ZVMXUJT 7KU7FW35LYUE
GZ3Y6YS434ZM OEMV0ZV6ZJ50 531624UX0ZXC

(I've padded some lines out to even letters with an "X")

The advantage of this over other, simpler, substitution ciphers is that the normal frequency analysis (counting the amount of times a letter occurs) doesn't work as well as there are 36*35 letter pairs, rather than just 36. A weakness is that pairs can be the reverse: "BR" comes out as "PD", but "RB" comes out as "DP", a property which can be exploited by a cryptanalyst who knows that this cipher is being used.

Playfair wasn't particularly secure, but then it wasn't meant to be. It had to last just long enough for the information to be effective: by the time the enemy had broken the code, it was already too late! For this reason, it's sometimes known as a tactical cipher.

No comments:

Post a Comment