Playfair Tutorial

Introduction

The Playfair cipher is a digraphic substitution cipher based on a 5 x 5 Polybius square formed with a keyword (N.B., I/J are considered equivalent). The plain text is broken up into two letter combinations (digraphs). Double letters are not permitted and must be separated by inserting a null (Usually an ‘X’). If a single letter is left at the end of the plain text, a null is also inserted there to complete the digraph.

The letters of each plain text digraph are found in the keysquare and a cipher text digraph is obtained by the following substitution scheme:

  1. If the plain text letters are in the same row, substitute the letters immediately to the right of them.
  2. If the plain text letters are in the same column, substitute the letters immediately below them.
  3. If the plain text letters are in neither the same row nor the same column, substitute the letters forming a rectangle with them. Begin with the letter that is in the same row as the first plain text letter.

Consider the following example:

  • Msg: The end is near.
  • Keyword: Robin
Keysquare:
           ROBIN
           ACDEF
           GHKLM
           PQSTU
           VWXYZ 

(Note, the keyword and alphabet can be placed in the key square in various ways. This shows just one example.)

PT: th ex en di sn ea rx
CT: QL DY FI EB UB FC BV

Note that the double ‘e’ formed by ‘the end’ was broken up with a null. Also note the null inserted at the end of the message to complete the final digraph. If you are not familiar with Playfair, study this example. The cryptanalysis of this cipher type requires a good working knowledge of the substitution scheme (And consequently I always have trouble with Playfair!).

Example

The example we will be working on is ND03 E-18:

E-18. Playfair. Practical Cryptanalysis. LIFER

SQ PD GQ EC BP UI LN QL LD DI ZC SR CZ HD FO DK QF AR LV HQ BM GR
WL SB SB QR UI WH UH MB GS ID CZ IU SQ HU CN CH KR LN SF IK SL UD
QW                                         (Ends: to be broken x)

Lining up the crib and the cipher text we get:

01 02 03 04 05 06
*t ob eb ro ke nx
LN SF IK SL UD QW

Not that digraphic pairs 02 and 04 share some of the same plain text (i.e., ‘o’) and cipher text characters (i.e., ‘S’). We will start the analysis with these two sets:

The digraphic pair (ob:SF) must be formed from the keysquare in one of the three ways discussed above. That means the keysquare must look like one of the following:

(1)  O . S   (2) O S . B F   (3) O
     . . .                       S
     F . B                       .
                                 B
                                 F

(Note the ‘.’ denotes possible intervening row and columns).

Number (1) looks the most promising. The letters ‘F’ and ‘B’ are in the same row. If they were not in the keyword, we would expect that these two letters might be arranged closely like this. (The validity of this assumption depends on how the constructor put the letters into his keysquare.) We will start with (1) as a guess.

Also, the digraphic pair (ro:SL) must be formed from the keysquare in one of the three ways discussed above. That means the keysquare must look like one of the following:

(4)  S . R   (5) O L . R S   (6) O  
     . . .                       L  
     O . L                       .
                                 R
                                 S

Note that of the three possibilities, only (5) is consistent with (1) (i.e., ‘O’ and ‘S’ are in the same row). Combining the two provides:

  O L . R S
  . . . . .
  F . . . B

Now lets try to fit digraphic pair 03 (eb:IK). This provides:

  O L . R S . .
  . . . . . . .
  F . . . B . K
  . . . . . . .
  . . . . I . E

Note that this places the letter ‘K’ in the same row as the letter ‘F’. This seems reasonable if the ‘BFK’ row is not part of the keyword.

Now lets try to fit digraphic pair 05 (ke:UD). Since ‘K’ and ‘E’ are already in the tentative keysquare, this provides:

  O L . R S . .
  . . . . . . .
  F . . . B . K
  . . . . . . U
  . . . . . . .
  . . . . I . E
  . . . . . . D

Note that we now have one column (‘KUED’) and one row (‘OLRS’) with four characters. It is likely that one of the letters in the ‘KUED’ column is also in the ‘OLRS’ row. This would complete the row and begin to collapse the keysquare to it’s final 5 x 5 size. Now, the ‘OLRS’ is likely to be in the keyword part of the square based on the sequencing of ‘O’ and ‘L’. If we move the letter ‘D’ up to the first row, we can form the word ‘OLD’ or ‘SOLD’. Further, the ‘BFK’ row would likely be the first row after the keyword based on alphabetic order. Based on these guesses, we get:

  . I . . E
  R S O L D 
  . B F . K
  . . . . U
  . . . . .

(Note that the ‘.’ symbols now just denote empty positions.)

Note the position of the letter ‘U’. This is perfectly placed if the row below it contains the end of the alphabet (i.e., ‘VWXYZ’). Filling this in we get:

  . I . . E
  R S O L D 
  . B F . K
  . . . . U
  V W X Y Z

Now lets look at the last unused digraphic pair from the crib. Pair 06 provides (nx:QW). The positions of ‘X’ and ‘W’ are know. This allows only one positioning of ‘N’ and ‘Q’ as follows:

  . I . . E
  R S O L D 
  . B F . K
  . N Q . U
  V W X Y Z

Note that since the ‘R’ and ‘S’ are already located in the keysquare, ‘T’ must fit between ‘Q’ and ‘U’. Further, since ‘L’ is already placed in the keysquare, ‘M’ must be positioned just before ‘N’. This provides:

  . I . . E
  R S O L D 
  . B F . K
  M N Q T U
  V W X Y Z

Now, let’s substitute this partial keysquare into the con and see what we get:

  * I * * E
  R S O L D 
  * B F * K
  M N Q T U
  V W X Y Z
C:  SQ PD GQ EC BP UI LN QL LD DI ZC SR CZ HD FO DK QF AR LV HQ BM GR
P:  on ** ** ** ** ne st to ol se ** rd ** ** o* ed fo ** ry ** *n ** 

C:  WL SB SB QR UI WH UH MB GS ID CZ IU SQ HU CN CH KR LN SF IK SL UD
P:  ys is is mo ne ** ** n* ** es ** en on ** ** ** *d st ob eb ro ke

C:  QW
P:  nx

At this point, partial words are apparent in the plain text (e.g., ‘*nest tools e**r’). It is a matter of filling in the last few positions in the keysquare based on guesses for this plain text and uncovering the keyword for the square. At this point, you should be able to finish decrypting this con yourself.