Polymapping N-gram cipher.
This cipher was used as part a challenge in Cyber Discovery's "Content Creators Club CTF", CH06. You can see writeup.md for a writeup of this challenge, which also serves of a usage example for this cipher.
cipher.py is a script that provides an implementation of encryption/decryption using this cipher. Because of the way decryption works (see below), it relies on word frequency as a heuristic for decryption at points, to simulate human judgement of the more likely decryption candidate.
The cipher is a substituion cipher with three additions. The first is that some plaintext characters encrypt to the same ciphertext character. As a result, when decrypting, some characters have two possible plaintext counterparts. These are indicated in bold and italics in the table below.
| Plaintext | Ciphertext |
|---|---|
| A | O |
| B | V |
| C | K |
| D | G |
| E | Y |
| F | F |
| G | Q |
| H | J |
| I | L |
| J | Q |
| K | K |
| L | M |
| M | R |
| N | T |
| O | W |
| P | B |
| Q | Z |
| R | A |
| S | C |
| T | P |
| U | X |
| V | X |
| W | N |
| X | Z |
| Y | H |
| Z | Z |
Additionally, certain N-grams in plaintext are encrypted into single characters. For clarity, these N-gram mappings and polymapped characters are summarised below.
| Plaintext | Ciphertext |
|---|---|
| ING | I |
| ST | S |
| EA | E |
| OU | U |
| TH | F |
----- |
----- |
| F, TH | F |
| C, K | K |
| G, J | Q |
| U, V | X |
| Q, X, Z | Z |
Finally, double letters are encrypted differently. In ciphertext, a double letter is notated by a D followed by the letter that is doubled. For example, the plaintext word BELL would encrypt to VYDM. The BE encrypts to VY, and L maps to M. Because M is prefaced with a D, it would expand to VYMM which then decrypts back to BELL.