Tool to encrypt and decrypt messages using the Quagmire IV cipher, a polyalphabetic substitution cipher based on two keyed alphabets (plaintext and ciphertext) and a periodic keyword.
Quagmire 4 Cipher - dCode
Tag(s) : Poly-Alphabetic Cipher
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
Quagmire IV is a periodic polyalphabetic substitution cipher, related to the Vigenère cipher.
It uses two mixed alphabets (plaintext and ciphertext) and a periodic keyword.
It belongs to the Quagmire cipher family and corresponds to plan K4.
Two methods can be used to encrypt a message.
Mathematical method: by numbering letters from A to Z from $ 0 $ to $ 25 $, encryption is expressed as $$ C = (P + K - I) \bmod 26 $$
— $ P $ is the rank of the plaintext letter in the mixed plaintext alphabet
— $ K $ is the rank of the periodic keyword letter in the mixed plaintext alphabet
— $ I $ is the rank of the indicator letter in the mixed ciphertext alphabet
— $ C $ is the rank of the encrypted letter in the mixed ciphertext alphabet
Visual method with a table:
Build the encryption table from the two mixed alphabets, the periodic keyword and the indicator letter.
Split the plaintext into blocks of $ N $ letters, where $ N $ is the length of the periodic keyword.
For each plaintext letter, locate its position in the mixed plaintext alphabet, then read the encrypted letter in the row corresponding to the periodic keyword letter, using the indicator letter column as reference.
Example: Encrypt DCODE using the mixed plaintext alphabet based on the keyword SECRET, the mixed ciphertext alphabet based on ALPHABET, the periodic keyword CODE (4 letters), and the indicator letter A (taken from the ciphertext alphabet). The encrypted message is FKUCH.
— Build the mixed plaintext alphabet by writing the first keyword without its repeated letters, then adding the remaining letters of the natural alphabet in their usual order.
Example: SECRET becomes SECRT from which the plaintext alphabet SECRTABDFGHIJKLMNOPQUVWXYZ is derived
— Build the mixed ciphertext alphabet using the second keyword.
Example: ALPHABET gives ALPHBETCDFGIJKMNOQRSUVWXYZ
— Choose an indicator letter from the mixed ciphertext alphabet. This letter indicates the reference column.
— Choose a periodic keyword and build the rows of the table so that each row contains the mixed plaintext alphabet shifted so that the periodic keyword letter (taken from the plaintext alphabet) appears in the indicator letter column.
Example: The periodic keyword is CODE, the indicator letter is A, the Quagmire IV table is:
| Key | S | E | C | R | T | A | B | D | F | G | H | I | J | K | L | M | N | O | P | Q | U | V | W | X | Y | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| (1) | P | H | B | E | T | C | D | F | G | I | J | K | M | N | O | Q | R | S | U | V | W | X | Y | Z | A | L |
| (2) | I | J | K | M | N | O | Q | R | S | U | V | W | X | Y | Z | A | L | P | H | B | E | T | C | D | F | G |
| (3) | H | B | E | T | C | D | F | G | I | J | K | M | N | O | Q | R | S | U | V | W | X | Y | Z | A | L | P |
| (4) | A | L | P | H | B | E | T | C | D | F | G | I | J | K | M | N | O | Q | R | S | U | V | W | X | Y | Z |
Decryption is the reverse operation of encryption. It requires knowledge of the first keyword or mixed plaintext alphabet, the second keyword or mixed ciphertext alphabet, the periodic keyword, and the indicator letter in order to reconstruct the table.
Split the ciphertext into blocks of $ N $ letters, where $ N $ is the length of the periodic keyword.
For each encrypted letter, locate that letter in the header (mixed ciphertext alphabet), then read the plaintext letter in the row corresponding to the current position of the periodic keyword, at the found column.
Example: The ciphertext VEDFQWTL decrypts to 'QUAGMIRE' (with the same alphabets and keyword used previously)
In the classic Vigenère cipher, the plaintext and the cipher alphabets use the natural alphabet from A to Z. Each cipher alphabet corresponds to a rotation of this alphabet.
In Quagmire IV, the alphabet used to locate plaintext letters is mixed using the first keyword, while the cipher alphabet is mixed using the second keyword. Moreover, the indicator letter is taken from the ciphertext alphabet.
Decryption therefore requires recovering both mixed alphabets, the periodic keyword and the indicator letter.
The markers are similar to the Vigenère cipher, but frequency analysis is made more complex by the presence of two mixed alphabets and by the use of an indicator letter taken from the ciphertext alphabet.
dCode retains ownership of the "Quagmire 4 Cipher" source code. Any algorithm for the "Quagmire 4 Cipher" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Quagmire 4 Cipher" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Quagmire 4 Cipher" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Quagmire 4 Cipher" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Quagmire 4 Cipher on dCode.fr [online website], retrieved on 2026-11-05,