Clever Quest Lab ← Labs

Playfair Cipher

Build a 5×5 key square from a keyword, encrypt letter pairs and watch every rule at work.

Encrypt & decrypt

Samples:

Key square

keyword (bar)inputoutput

Pair 1 of 13Rectangle

Preparing the plaintext, step by step

    Weaknesses, measured on this text

    1. Pair frequencies survive

    plaintext pairits ciphertext pairNumber of times each pair occurs.

    #PlainCipherTimes

    2. Reversed pairs stay reversed

      Ciphertext in pairs. Outlined pairs belong to the couples listed above (up to eight); the small number shows which couple.

      3. No doubled letters in a pair

      Ciphertext pairs
      0
      Doubled pairs
      0
      Random letters would give
      0
      Fillers that prevented one
      0

      4. No letter encrypts to itself

      Letters compared
      0
      Same letter in the same place
      0
      Random letters would give
      0
      Distinct pairs used
      0

      Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves only the direction, alphabet, filler letter and output format on this device.

      Added

      How to use it

      Type a keyword. The 5×5 key square updates as you type: the keyword’s letters come first, each only once, followed by the rest of the alphabet in order. Then type or paste a text into the left box and the right box shows the result at once. Choose Encrypt or Decrypt at the top; both directions need the same keyword and settings. To check the round trip, press “Use the result as input”.

      Playfair works on letter pairs, so the text is prepared first; the panel below the boxes shows each stage. Spaces, digits and punctuation are dropped (write numbers as words), letters with diacritics such as é or ü become plain letters, and everything is written in capitals. J becomes I, because I and J share one cell; with “Omit Q” every Q is removed instead. The letters are then split into pairs. When both letters of a pair would be the same, as in the EE of TREE, a filler letter goes between them, and a single letter left at the end gets the filler too. If the doubled letter is the filler itself, the next letter of the list X, Q, Z is used instead, skipping Q when the square has no Q.

      Controls

      How it works

      Number the rows and columns of the square from 0 to 4. A pair of two different letters at (r1, c1) and (r2, c2) is encrypted by one of three rules, where rows and columns wrap around:

      same row: (r, c) → (r, c + 1 mod 5)
      same column: (r, c) → (r + 1 mod 5, c)
      rectangle: (r1, c1), (r2, c2) → (r1, c2), (r2, c1)

      Decryption uses the inverse rules: the letter to the left, the letter above, and the rectangle rule again, which undoes itself. The fillers come back in the decrypted text. A reader removes them by sense, so the page marks the likely ones under the result: a filler between two equal letters, or at the very end.

      With the keyword PLAYFAIR EXAMPLE, I and J merged and filler X, “Hide the gold in the tree stump” becomes BMODZBXDNABEKUDMUIXMMOUVIF. Charles Wheatstone invented the cipher in 1854. It is named after Lord Playfair, who promoted its use.

      The four cards above the article measure the weaknesses on your own text. Each plaintext pair always becomes the same ciphertext pair, so pair frequencies survive; with enough text, the most common ciphertext pairs point to common English pairs such as TH, HE, IN and ER. If AB becomes XY, then BA becomes YX, because all three rules treat the two letters the same way, so words like ER and RE leave matching reversed pairs. Finally, a ciphertext pair never has a doubled letter and no letter ever encrypts to itself, because every rule moves a letter to another row or column. In random letters, about one pair in 25 would be doubled and about one letter in 25 would match.

      Things to try

      Frequently asked questions

      Why do I and J share one cell?

      A 5×5 square has 25 cells for 26 letters, so one letter has to go. J is rare in English and still reads well as I, so merging I and J is the usual choice. Leaving out Q is the other common option.

      Why is there an extra X in my decrypted text?

      It is a filler or padding letter added before encryption. The cipher cannot tell a filler from a real X, so a person drops it while reading. The reading aid under the result marks the likely ones.

      Can Playfair encrypt digits?

      No. The square holds letters only, so digits, spaces and punctuation are dropped. Write numbers as words, for example SEVEN.

      Is the Playfair cipher secure today?

      No. Working on pairs hides single-letter frequencies better than a simple substitution, but pair frequencies and the reversed pairs remain. It can be broken by hand with enough ciphertext, and computer programs that try and improve key squares break it quickly.

      Sources