Polybius Square

Introduction

The Polybius square dates back to somewhere between 200 and 120BC and is an important tool for codes and ciphers. Depending on the means of communication, the square describes a code for representing an alphabet using a smaller set of characters.

Example

Polybius was a Greek historian, so his square would have been filled with Greek letters. Here is a version with our alphabet,

 12345
1ABCDE
2FGHI/JK
3LMNOP
4QRSTU
5VWXYZ

Letters can now be described using their co-ordinates. The letter 'H' would be described with 23. It is the third letter in the second row. To keep the square dimensions to a minimum, the letters 'I' and 'J' share a grid space.

Clearly, by itself, this is no great way to keep something secret. Its main benefit is providing a way to represent a full alphabet when only a limited range of symbols is available. It does form the basis of a range of other ciphers used throughout history and, this way of representing letters is at the core of the algorithms employed in the other ciphers in this section.

Challenges

The first challenge would be to create a two dimensional array to store the letters of the square. Given any letter, your program would need to be able to return its coordinates in the grid in row, column order.

Next you could make a random grid to use for encrypting and decrypting.

More interesting would be to use the square as the key for your own invention. How about you swap the co-ordinates of the letters to form your cipher text?