Polybius Square Cipher

Introduction §

The Polybius Square is essentially identical to the simple substitution cipher, except that each plaintext character is enciphered as 2 ciphertext characters. It can ususally be detected if there are only 5 or 6 different characters in the ciphertext.

This algorithm offers very little communication security, and can be easily broken even by hand, especially as the messages become longer (more than several hundred ciphertext characters).

Example §

Here is a quick example of the encryption and decryption steps involved with the Polybius Square. The text we will encrypt is 'defend the east wall of the castle'.

Keys for the Polybius Square usually consist of a 25 letter 'key square'. e.g. (the letters along the top and side can be chosen arbitrarily):

   A B C D E
A| p h q g m
B| e a y l n
C| o f d x k
D| r c v s z
E| w b u t i

An example encryption using the above key:

plaintext:  d e f e n d  t h e  e a s t  w a l l  o f  t h e  c a s t l e 
ciphertext: CCBACBBABECC EDABBA BABBDDED EABBBDBD CACB EDABBA DBBBDDEDBDBA

It is easy to see how each character in the plaintext is replaced with 2 characters in the cipher alphabet. Decryption is just as easy, by using 2 cipher characters as the row and column into the key square to get the original plaintext character back. When generating keys it is popular to use a key word, e.g. 'zebra' to generate it, since it is much easier to remember a key word compared to a random jumble of 25 characters. Using the keyword 'zebra', the key would become (i/j are combined):

cipher alphabet: zebracdfghiklmnopqstuvwxy

Here we have written out the key as a single string instead of a square. To create the square, the first 5 characters make the first row, the second 5 characters make the second row etc.

If your keyword has repeated characters e.g. 'mammoth', be careful not to include the repeated characters in the cipher alphabet.

It is interesting to note that the ADFGVX cipher uses a 6x6 version of the polybius square as the first step in its encryption.

JavaScript Example of the Polybius Square §

Plaintext

key =

Ciphertext characters:

Ciphertext

Other Implementations §

To encipher your own messages in python, you can use the pycipher module. To install it, use pip install pycipher. To encipher messages with the Polybius square cipher (or another cipher, see here for documentation):

>>>from pycipher import PolybiusSquare
>>>p = PolybiusSquare('phqgiumeaylnofdxkrcvstzwb',5,'ABCDE')
>>>p.encipher('defend the east wall of the castle')
'CEBCCDBCCBCEEBABBCBCBDEAEBEDBDCACACCCDEBABBCDDBDEAEBCABC'
>>>p.decipher('CEBCCDBCCBCEEBABBCBCBDEAEBEDBDCACACCCDEBABBCDDBDEAEBCABC')
'DEFENDTHEEASTWALLOFTHECASTLE'

Cryptanalysis §

The Polybius Square is quite easy to break, since it is just a substitution cipher in disguise. This means that the whole section on cryptanalysing substitution ciphers is applicable, and will not be repeated here. The only minor difference is that cryptanalysis must now be done on pairs of characters instead of single characters.

References §

  • Wikipedia has a good description of the encryption/decryption process, history and cryptanalysis of this algorithm
  • Simon Singh's 'The Code Book' is an excellent introduction to ciphers and codes, and includes a section on substitution ciphers.
  • Singh, Simon (2000). The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography. ISBN 0-385-49532-3.

Simon Singh's web site has some good substitution cipher solving tools:

comments powered by Disqus

Further reading

We recommend these books if you're interested in finding out more.

Cover of Cryptanalysis: A Study of Ciphers and Their Solution Cryptanalysis: A Study of Ciphers and Their Solution ASIN/ISBN: 978-0486200972 Buy from Amazon.com
Cover of Elementary Cryptanalysis: A Mathematical Approach Elementary Cryptanalysis: A Mathematical Approach ASIN/ISBN: 978-0883856475 Buy from Amazon.com
Cover of The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography ASIN/ISBN: 978-1857028799 Simon Singh's 'The Code Book' is an excellent introduction to ciphers and codes Buy from Amazon.com
YBL KRQ IBF KFNLH R KFSQYRDQ MLXDQH MV TRPPVDQX - TFQZSTDSH