Playfair Cipher Encoder & Decoder
指导
Playfair Cipher Encoder & Decoder
Encrypt or decrypt text with the classic Playfair cipher entirely in your browser. Enter a keyword, paste your plaintext or ciphertext, and watch the tool build the 5×5 keyed matrix, prepare the digraphs, and walk through every substitution step. No data ever leaves your device.
如何使用
- 选择一种模式: 编码 to turn plaintext into ciphertext, or 解码 to recover the original message.
- Type or paste your text into the input box. Punctuation, digits and spaces are ignored.
- Enter a keyword (any alphabetic word or phrase). Duplicates are stripped when the 5×5 matrix is built.
- Choose a matrix variant: I/J share a cell (the original 1854 form) or Omit Q (J kept separate).
- Optionally change the filler letter used to split doubled pairs and pad odd-length plaintexts.
- Read the result, inspect the keyed matrix, and review the digraph-by-digraph breakdown below.
特征
- Visual 5×5 keyed matrix – Keyword letters are highlighted so you can see how the grid is built.
- Both classic variants – Choose I/J fold or Omit-Q to match whichever historical Playfair flavor you need.
- Automatic digraph preparation – Doubled letters get a filler split, odd-length input gets padded, and inserted filler characters are highlighted.
- Step-by-step substitution table – Each digraph is shown with the rule applied (same row, same column, or rectangle) and the output pair.
- Configurable filler letter – Pick X, Q, or Z depending on what fits your plaintext best.
- Encode and decode in one tool – Round-trip your messages without switching pages.
- Entirely client-side – Encryption runs in pure JavaScript, so your messages and keywords never touch our servers.
常问问题
-
Why does the Playfair cipher use a 5x5 grid instead of 6x5 or 5x6?
A 5x5 grid holds exactly 25 letters, one short of the English alphabet. The original cipher squeezed the alphabet to 25 by folding I and J into a single cell. A 5x5 layout also keeps the row, column, and rectangle rules symmetric and easy to apply by hand — a 6x5 or 5x6 grid would force the rules to handle differing wrap-around sizes per axis, which would be impractical for the pencil-and-paper use the cipher was designed for.
-
Why does Playfair encrypt pairs of letters instead of single letters?
Encrypting digraphs flattens letter-frequency statistics. In English the letter E appears about 12.7% of the time, but the digraph TH appears only around 2.7%. Because Playfair maps each plaintext digraph to a unique ciphertext digraph, single-letter frequency analysis fails. This is what made Playfair dramatically harder to break than monoalphabetic ciphers like Caesar.
-
What is the difference between the I/J variant and the Omit-Q variant?
Both variants squeeze 26 letters into 25 cells. The I/J variant treats I and J as the same letter — any J in the plaintext is replaced with I before encoding. The Omit-Q variant drops Q entirely from the matrix; texts containing Q must be rewritten before encoding (often as KW or simply omitted). I/J is the historically correct form used by British forces; Omit-Q is sometimes preferred for texts where I and J carry independent meaning, such as legal documents.
-
Why does decoding produce extra X letters in the plaintext?
Playfair cannot encrypt a digraph made of two identical letters because the encoding rules require the pair to be in different positions on the grid. The encoder splits such pairs by inserting a filler letter (commonly X). The decoder is rule-based and has no way to know which X letters were original and which were inserted, so the recovered plaintext contains the filler. Removing fillers is a manual post-processing step left to the reader.
-
Is the Playfair cipher still secure today?
No. Playfair was considered field-secure for short tactical messages in the 19th and early 20th centuries, but modern cryptanalysis breaks it easily. Digraph frequency analysis on a few hundred letters of ciphertext usually reveals enough of the matrix to recover the rest with hill-climbing or simulated annealing. Treat Playfair as an educational tool, a puzzle device, or a historical exercise — not a real-world encryption scheme.
