Playfair cipher assistant

You must have JavaScript enabled in your browser in order to use the Playfair application.

The Playfair cipher is a cryptographic cipher that was devised in the 19th century. It is far too weak to be used in modern cryptography, but it is occasionally used in thematic cryptic crosswords such as the Azed, which appears in the Observer newspaper (UK), and the Listener crossword, which appears in the Saturday edition of the Times newspaper (UK). This application is intended to assist in solving the Playfair element of those crossword puzzles.

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Keyword:
Padding:
Plaintext:
Ciphertext:
Mappings:
Solutions:
Maximum number of solutions:

The user interface of the Playfair application consists of two panels:

Performing encryption and decryption

Encryption and decryption are controlled with the components in the upper panel of the user interface. Before you can encrypt or decrypt, you must set the key of the cipher by entering the keyword in the Keyword field and then clicking the Set key button. When a key is set, the code square will be updated and the Plaintext and Ciphertext fields and their adjacent buttons, Encrypt and Decrypt, will be enabled.

The Playfair alphabet consists of 25 letters, which, by convention, are the 26 letters of the English alphabet without the letter J. I serves for both I and J: when setting a key or performing encryption, any occurrences of the letter J in the keyword or plaintext are replaced by I.

In creating a key from a keyword, only the first occurrence of a particular letter is used; subsequent occurrences of the letter are ignored. The remaining letters of the Playfair alphabet are appended in alphabetical order to the sequence of unique letters from the keyword. For example, if the keyword were PSEUDORANDOM, the key of the cipher would be PSEUDORANMBCFGHIKLQTVWXYZ.

To perform encryption, enter the word to be encrypted in the Plaintext field and click the Encrypt button. The encrypted word will be displayed in the Ciphertext field. Conversely, to perform decryption, enter the word to be decrypted in the Ciphertext field and click the Decrypt button. The decrypted word will be displayed in the Plaintext field.

Because the Playfair cipher operates on pairs of letters, the length of plaintext and ciphertext must be even. In some crosswords, plaintext with an odd number of letters is allowed by appending a specified letter to it, thereby padding it to an even length for encryption. In such cases, you can select the letter from the Padding drop-down list; when encrypting, the selected letter will be appended automatically to plaintext whose length is odd.

When a word is encrypted or decrypted, it is split into a sequence of pairs of letters. Pairs of identical letters are not allowed in either the plaintext or the ciphertext, though two successive identical letters are allowed if they don't correspond to a logical pairing. For example, ASSENT (AS-SE-NT) is allowed but PASSED (PA-SS-ED) is not.

If you press the Enter key when one of the three text fields has keyboard focus, it will have the same effect as clicking the button adjacent to the field.

Searching for solutions to a Playfair cipher

The search for solutions to a Playfair cipher is controlled with the components in the lower panel of the user interface. To perform the search, you must enter some mappings from plaintext to ciphertext in the Mappings text area, then click the Solve button.

A mapping is a line of text consisting of plaintext and ciphertext separated by whitespace (spaces (U+0020) or tab characters (U+0009)). The plaintext must consist entirely of letters, while the ciphertext may contain either letters or ? characters (U+003F), with each ? character denoting an unknown letter. The plaintext and ciphertext must have the same length, which must be even. Pairs of identical letters in either the plaintext or the ciphertext are not allowed if the letters correspond to a logical pairing, as described in the previous section. There may be whitespace before the plaintext or after the ciphertext.

The text in the Mappings area may consist of multiple lines, with no more than one mapping per line. Blank lines are ignored. The # character (U+0023) is deemed to introduce a comment, and any text from a # character to the end of the line is ignored. The mappings must contain at least one complete mapping from a pair of plaintext letters to a pair of ciphertext letters (that is, one in which both ciphertext letters are specified).

You can limit the number of solutions that will be found in a search by entering the required value in the Maximum number of solutions field. By default, the upper limit is 500 solutions, which is the number of solutions for the minimal mapping from a pair of plaintext letters to a pair of ciphertext letters. Solutions are not found in order of their plausibility: if the upper limit is too low, the best candidate may be missed.

When you have entered all the mappings in the Mappings text area, click the Solve button to begin the search for solutions. If there are no errors in the mappings, a list of the solutions that are found will be displayed in the Solutions text area.

If there are errors in any of the mappings (eg, the plaintext and ciphertext are of different lengths), a message relating to the first error will be displayed and the Solutions area will be cleared. A line number in an error message is one-based (ie, the first line of text is line 1). An index in an error message denotes the zero-based index of a letter in the plaintext or ciphertext of a specified line.

The list of solutions is preceded by some information about the search: the maximum number of solutions and the number of solutions that were found. Each solution consists of a Playfair square in linear form (ie, a possible key for the cipher), with a dot in the place of each unknown entry. Unless the mappings contain information on all 25 letters, the key will be incomplete, and you will have to infer the missing letters. The number in parentheses after each solution is the minimum length of the keyword, which is calculated from the length of the "tail" — the letters in alphabetical order that follow the keyword. (In a fancier user interface, the letters of the solution corresponding to the minimum length would be highlighted.) The solutions are listed in order of increasing minimum length of the keyword, and the more plausible keywords will be found towards the top of the list.

The following example contains several mappings for Playfair-encrypted entries in a crossword. The keyword, OBSERVANTLY, appears as a comment:

# OBSERVANTLY

ANYHOW   N?HQ??
MELTED   XT??SF
LINCTURE ??ADAX?R
RIBOSOME B?SBEB??
BECALM   SR??TP
OUTFIT   ??FM?A

If you copy the example, paste it into the Mappings text area and click the Solve button, a list of 100 solutions should be displayed in the Solutions text area. The keyword, OBSERVANTLY, with the V missing, is the second item in the list. (In this example, BSEROANTLY is also a valid keyword, but is unlikely to be the keyword for a crossword because it is not a word in the English language.)

Notes on the Playfair application

  1. The JavaScript for the Playfair application on this page is free software, distributed under version 3 of the GNU General Public License.
  2. In the application, the conventional character map in which occurrences of the letter J in the keyword or plaintext are replaced by I is implemented by the CharacterMap class. If you want a different mapping, you can modify CharacterMap.DEFAULT_OUT_CHARS.