Digraph Cipher Encoder & Decoder
Select a cipher variant, enter your keyword and message, then encode or decode instantly with step-by-step breakdown.
Encrypt and decrypt messages using powerful digraph cipher algorithms — Playfair, Four-Square, and Two-Square. 100% client-side processing, no data ever leaves your browser.
Select a cipher variant, enter your keyword and message, then encode or decode instantly with step-by-step breakdown.
Everything you need to master digraph ciphers in one place.
Choose from Playfair, Four-Square, and Two-Square ciphers. Each offers unique key structures and encryption strength for different cryptography use cases.
Instantly see your generated 5×5 key square update as you type. Highlighted cells show which letters are keyed, making cryptanalysis education easy.
Watch every digraph pair get processed with annotated rules — same row, same column, or rectangle swap — so you learn while you encrypt.
Input validation fires as you type. Invalid characters, keyword conflicts, and empty fields are flagged immediately with clear guidance to fix them.
All encryption and decryption happens entirely in your browser using JavaScript. No data is ever sent to any server, ensuring complete privacy.
Copy output to clipboard with a single click or download your encoded/decoded message as a .txt file for offline use or documentation.
Understanding the encryption algorithm step by step.
Write your keyword (removing duplicates), then fill remaining letters A–Z (excluding J) into a 5×5 matrix in order.
Split plaintext into digraph pairs. Insert X between repeated letters and after single letters to complete a pair.
For each pair: same row → shift right, same column → shift down, otherwise → swap rectangle corners.
Concatenate all encrypted pairs. The result is a ciphertext that requires the same keyword and algorithm to reverse.
A digraph cipher is a classical encryption technique that operates on pairs of letters — called digraphs — rather than individual characters. This fundamental distinction makes digraph ciphers dramatically more resistant to standard frequency analysis attacks compared to monoalphabetic substitution ciphers, where single-letter patterns reveal the key almost instantly.
The most celebrated digraph cipher is the Playfair cipher, invented by Charles Wheatstone in 1854 and popularized by Lord Lyon Playfair. It became the first literal digraph cipher in widespread military use, employed by the British Army during the Boer War and World War I. Its 5×5 key square design meant that even if an adversary intercepted a message, recovering the plaintext without knowing the keyword was a formidable challenge for the era.
Encoding with a digraph cipher begins by constructing a 5×5 keyword matrix. You fill the grid with your chosen keyword (removing duplicate letters), then complete it with the remaining alphabet (I and J typically share one cell). The plaintext is split into letter pairs. If two letters in a pair are identical, a filler character (usually X) is inserted. Three rules then govern each pair: letters on the same row shift one position right; letters in the same column shift one position down; and all other pairs swap to their rectangle's opposite corners.
Decoding is the mirror operation. Using the same keyword matrix, you reverse each rule — same row shifts left, same column shifts up, rectangle pairs swap back. The skill lies in recognizing the padding characters and stripping them to recover the original message cleanly.
More advanced variants extend the digraph concept. The Four-Square cipher, devised by Felix Delastelle in 1901, uses four 5×5 squares — two plain alphabet squares at the corners and two keyed squares in the centre — doubling the key complexity. The Two-Square cipher arranges two keyed grids horizontally or vertically, offering different trade-offs between security and ease of hand-encryption.
For production security, always use modern cryptographic standards such as AES-256 or ChaCha20. Digraph ciphers are vulnerable to known-plaintext attacks and skilled cryptanalysts can break them with sufficient ciphertext. Treat them as educational tools and recreational instruments rather than secure communication channels.
Discover our full library of 100+ free developer and utility tools — from cryptography and encoding to AI tools, converters, and more.
Browse our complete collection of developer utilities and online tools.