Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The ADFGVX Cipher

In the spring of 1918, near the end of World War I, the German army began sending radio messages in a new cipher designed by Lieutenant Fritz Nebel. The first version, used from March 1918, was called ADFGX. On 1 June 1918 it was replaced by a bigger version, ADFGVX. The names come from the only letters that ever appear in the ciphertext. They were chosen because they sound very different from one another in Morse code, so radio operators were less likely to mix them up.

ADFGVX isn’t a block cipher, but it shows three of the ideas from the introduction to block ciphers:

  • Confusion. Each plaintext character is replaced using a secret table.

  • Fractionation. Each plaintext character becomes two ciphertext symbols, and a transposition then pulls the two symbols apart.

  • Diffusion. Because the two symbols end up in different parts of the ciphertext, each plaintext character affects more than one place in the message.

Encryption has two stages: a substitution with a Polybius square, then a columnar transposition with a keyword. The key is the square and the keyword together.

The sections below go through each stage.

Stage 1: The Polybius Square

A Polybius square is a grid with a letter label on each row and each column. ADFGVX uses a 6×6 square labelled A D F G V X, which has room for the 26 letters and the 10 digits. (ADFGX used a 5×5 square with I and J sharing a cell, so it had no digits.) The arrangement of the 36 symbols is part of the secret key.

Here is the square for an encryption example.

ADFGVX
AP042R9
DCUW5AE
FOH3LQM
GN7SBYG
VTIJ1VZ
X6KX8FD

To substitute a character, find it in the square and write its row label, then its column label. For example, M is in row F, column X, so it becomes FX. The 4 is in row A, column F, so it becomes AF.

PlaintextMATH4LIFE
SubstitutionFXDVVAFDAFFGVDXVDX

So MATH4LIFE becomes FXDVVAFDAFFGVDXVDX, which is twice as long as the plaintext.

In Python, store the square as one string of 36 characters, read row by row. A character at position p in the string sits in row p // 6 and column p % 6.

   A D F G V X
A   P 0 4 2 R 9
D   C U W 5 A E
F   O H 3 L Q M
G   N 7 S B Y G
V   T I J 1 V Z
X   6 K X 8 F D
valid square: True
'FXDVVAFDAFFGVDXVDX'

Stage 2: Columnar Transposition

The second stage is a keyed columnar transposition, covered in detail on the columnar transposition page in Chapter 2. In short: write the symbols from stage 1 into a grid under the keyword, one row at a time (the last row may be short), then read the columns from top to bottom in alphabetical order of the keyword’s letters.

The example uses the keyword TIME. The grid has 4 full rows and a short last row. Reading the columns in the order E, I, M, T gives VDGV, XAFDX, DFFX and FVAVD, so the ciphertext is VDGVXAFDXDFFXFVAVD.

The functions below do the transposition in Python. They assume the keyword has no repeated letters, like all of the keywords on this page.

T I M E
F X D V
V A F D
A F F G
V D X V
D X

VDGVXAFDXDFFXFVAVD

Putting both stages together gives the whole cipher. Like the other encryption functions in this book, it returns uppercase ciphertext in blocks of 5, and decryption returns lowercase plaintext.

'VDGVX AFDXD FFXFV AVD'

Decryption

To decrypt, undo the two stages in reverse order. First undo the transposition, which means working out how long each column is (see deciphering a columnar transposition). Then look up each pair of symbols in the square, row label first.

This decryption example uses the ciphertext DGDDDAGDDGAFADDFDADVDVFAADVX, the keyword PRIVACY, and the square below.

ADFGVX
ANA1C3H
D8TB2OM
FE5WRPD
G4F6G7I
V9J0KLQ
XSUVXYZ
  1. The ciphertext has 28 symbols and the keyword has 7 letters. Since 28=4×728 = 4 \times 7, every column has 4 symbols.

  2. Undoing the transposition gives ADDDDDADAGVGADDDAFDGVFVFADDX.

  3. Look up the pairs in the square: AD is A, DD is T, DD is T, AD is A, and so on.

The message is ATTACKAT1200AM, “attack at 12:00 am.”

valid square: True
ADDDDDADAGVGADDDAFDGVFVFADDX
attackat1200am

The TIME example has a short last row: 18=4×4+218 = 4 \times 4 + 2, so the columns under T and I, the first two letters of the keyword, have 5 symbols, and the columns under M and E have 4. columnar_untranspose handles that, so the whole cipher decrypts it too.

'math4life'

Fractionation and Diffusion

Change one character of the plaintext, MATH4LIFE to MATH5LIFE, and compare the two ciphertexts.

VDGVXAFDXDFFXFVAVD
VDGVXAGDXDFFXFVDVD
changed positions: [7, 16] out of 18

The 4 became AF and the 5 became DG. Both of those symbols changed, but the transposition sent them to positions 7 and 16, far apart. One plaintext change still affects only 2 of the 18 ciphertext symbols. That’s far short of the block cipher goal of changing about half, but it’s more than any stream cipher does.

The bigger win is against frequency analysis. Every cipher before this one kept a simple link: one plaintext letter in, one ciphertext letter out, in a predictable place. Counting ciphertext letters was really counting plaintext letters in disguise. ADFGVX breaks that link in two ways.

  • The ciphertext only ever contains six symbols, so counting them tells you very little.

  • Each plaintext character is split into two symbols, and the transposition puts them in different columns. No single ciphertext position stands for a single plaintext character.

The order of the two stages matters. If you transposed first and substituted second, you would just be shuffling whole characters and then substituting them consistently, and frequency analysis would still work. The Bifid cipher also fractionates: it splits each letter into its row and column numbers in a square and mixes them before turning them back into letters.

Breaking ADFGVX

ADFGVX was attacked by Lieutenant Georges Painvin, a cryptanalyst in the French army. He broke ADFGX messages in the spring of 1918, and in early June 1918 he solved an ADFGVX message that showed where the German army planned to attack next, during General Erich Ludendorff’s spring offensive. Historians still debate how much this helped the French hold off the attack.

Painvin’s methods needed a lot of traffic. They relied on finding several messages sent with the same key that began in the same, predictable way (stereotyped beginnings), and on patterns in the ciphertext positions that had come from the same column of the transposition. So they worked only on days with heavy radio traffic. Those were also the days when the most important messages were sent.

Questions to Think About

Try making your own square and keyword, encrypting a short message, and decrypting it again. As you work, think about these questions.