Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a set of Playfair-enciphered data that I'm trying to crack without the key. I know I need to analyse bigrams; I've currently worked out what decrypts to th, er, in, and he, and have figured out where th and he are in the grid. However, now I'm stumped.

I've looked at the "Solution to Polygraphic Substitution Systems" field manual, but it didn't help. How do I complete the cryptanalysis of Playfair having a few bigrams decrypted and knowing where two of those go in the grid?

share|improve this question

There are several algorithms available which can attack a playfair cipher.

Hill climbing might be one option. Basically it starts with a random key (assuming it's the best one) and decrypts the cipher. The resulting clear text is scored using a fitness function. Then small changes are applied to the key and if the resulting clear text of the modified key scores better, the modified key is regarded as the best key and the process of applying small changes to the key starts over again until no better key can be found.

Sometimes Hill Climbing does not find the best solution, the algorithm gets stuck at a local maximum. An effective way to resolve this issue is to use the Shotgun hill climbing (refer to the wikipedia link provided above).

The Simulated Annealing Algorithm is another option, see also here.

Or you can use the Genetic Algorithm. The algorithm mimics the process of natural selection.

If you are interested in an online playfair breaker: I think here the hill climbing algorithm is used. It is coded in Javascript, so the source can be studied.

If you are interested in how a clear text can be scored: Quadgram Statistics as a Fitness Measure.

share|improve this answer

It's not elegant, but the brute force method is to write a program that creates a table of 25x25 digraphs (assuming i=j), yielding 625 rows. I'd also add a column that lists the relative frequency of each digraph (given enough ciphertext you can use that to identify frequent substitutions, as you already have done). You start off with 625! possible solutions, but after identifying n digraphs this drops to (625-n)! But if the longest word in the language is N digraphs long, then take a 2N section and decode that (preferably use a section that already has some digraphs decoded). I'm thinking the overall complexity becomes picking something like $\frac{(625-n)!}{(625-2N-n)!}$

share|improve this answer
The complexity is probably less than that since negative/linguistically impossible combinations also provide evidence. These can be tracked by listing bad choices in 625 columns, and placing an X in the cell if they are not to be considered. – zQAycX Jun 16 '15 at 22:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.