Playfair

OK soldier, time to learn the Playfair cipher. We'll have you coding and decoding in no time!

You start by drawing a 5x5 grid, like this.

Each message has a secret keyword. You need the keyword to decode the message.

Write the keyword into boxes along the grid.

For example, if the keyword was LAND:

Now fill the remaining spaces with the alphabet - leaving out the letters you have already used.

We need to fit the whole alphabet into 25 spaces, so we combine I and J in one space.

Now you're ready to code or decode messages. To encode a message, split it into pairs:

'ATTACK AT SIX AM' becomes 'AT TA CK AT SI XA MQ'. (if the we are one letter short, we add a Q.)

Look at the grid. For each pair, imagine drawing a box in your grid with those letters at the corners. Each letter is replaced by the letter in the opposite corner of the box.

So for 'AT', the A becomes D, and the T becomes R.

Try encoding the whole message.

'AT TA CK AT SI XA MQ'

There are a couple of weird cases to be aware of:

If both letters are on the same row, you don't swap them with each other – that would be too obvious. Instead, move both letters one space to the right. So LD would become AB. Wrap around if you hit the edge of the grid.

If the two letters are in the same column (one above the other), move them both down one place. AK would encode to ER.

If the pair is the same letter twice - like OO - then add a Q between them in the original message.

If you need an extra letter to make the last pair of letters, add a Q.

Now you know all the special rules, try encoding this message: 'GO NORTH TO OTHER BASE'

Finally, let's decode a message. You just follow the same process, but in reverse!

This message has the same secret key - LAND. The encoded message is: CNXOGRTYCFOPMD

Result

If you have completed all three activities, you have passed basic training. Congratulations!