---
title: "ADFGVX"
description: "The 1918 German field cipher. A 6×6 grid writes each letter or digit as two of A D F G V X, then a second key shuffles the columns."
canonical_url: "https://ciphers.agntn.dev/ciphers/adfgvx"
---
# ADFGVX

> The 1918 German field cipher. A 6×6 grid writes each letter or digit as two of A D F G V X, then a second key shuffles the columns.

<cipher-facts name="adfgvx">



</cipher-facts>

The German field cipher of 1918 had two steps. First a 6×6 substitution that turns every letter or digit into a pair from `ADFGVX`, six letters picked because they sound nothing alike in Morse. Then a columnar transposition with a second key. The grid holds A to Z and 0 to 9, `key` reorders it with the keyword first, duplicates removed. `transposition` is the second key: the pairs are written in rows under it and read out column by column in its alphabetical order, the same rule as [columnar](https://ciphers.agntn.dev/ciphers/columnar). Anything that isn't a letter or a digit is dropped.

```ts
const adfgvx = create("adfgvx");
const keys = { key: "147 regiment", transposition: "privacy" };
adfgvx.encode("attack at 1200am", keys).text; // "DXXVGDADDAAXDVDXVFGVGFADDVVD"
adfgvx.decode("DXXV GDAD DAAX DVDX VFGV GFAD DVVD", keys).text; // "ATTACKAT1200AM"
adfgvx.encode("ATTACK AT 1200").text; // "AAGDGDAAAFDVAAGDVGVVVFVF"
adfgvx.decode("AAGDG"); // CipherError: Invalid ADFGVX code: 5 letters A, D, F, G, V and X, not whole pairs
```

Leave `transposition` out and you get the grid step alone, which is half a cipher: fine for a puzzle that only uses the grid, useless against a real 1918 message. Decoding drops everything but the six letters before undoing the columns, so the five-letter groups of a telegram go in as printed. Every letter or digit is a pair, so an odd count means one went missing on the way. Decoding says so instead of handing back a shorter message. Text with none of the six letters is an error too, not an empty answer.


## Sitemap

See the full [sitemap](https://ciphers.agntn.dev/sitemap.md) for all pages.
