# How many keys does the Playfair Cipher have?

I was just studying the Playfair cipher and from what I've understood, it is just a slightly better version of a Caesar cipher, in that it isn't actually mono-alphabetic but rather the 'digrams' are mono-alphabetic. I believe that since it offers a larger combination i.e 26*26=676 digrams, it is better than a Caesar Cipher which would give us a maximum of twenty-six keys. So does this mean that the Playfair Cipher have 676 keys including the duplicate or is it larger than that ?

## 2 Answers

When we consider that a Playfair key consists of the alphabet (reduced to 25 letters) spread on a 5x5 square, that's $25!$ keys (another formulation consider any string to be a key; then strings leading to the same square are equivalent keys).

The rules of Playfair are such that any rotation of the lines in the square, and any rotation of its columns, lead to an equivalent key (in other words, the square reduce to a torus). It can be proven conclusively that there are no other equivalent keys (note: a transposition of line/columns leads to a key such that 200 out of 600 digrams with distinct letters are mapped to the same diagram as for the original key, and the other 400 are mapped to the digram obtained by exchanging the two letters in the digram mapped by the original key; also, an horizontal or [resp. and] vertical mirroring of the square leaves 500 (resp. 400) digrams invariants; these are near-equivalent related keys, but not equivalent keys).

I conclude Playfair has $25!/{5^2}=620448401733239439360000\approx2^{79}$ distinct keys classes (a 79-bit-key cipher). At least another source agrees.

This is much less than an arbitrary permutation of digrams with distinct letters, which allows $(25\cdot24)!\approx2^{4678}$ keys.

If that's a homework question, I find it excellent to illustrate the notions of equivalent keys, key space, and why a big keyspace is not sufficient for security.

Counting duplicate keys, it would be $25!$ (remember i=j in playfair). Basically the key is the 5x5 square. There are $25!$ permutations of the $25$ characters which populate that square.