The rail fence cipher has very few keys, and its key is just a number. A keyed columnar transposition uses a keyword instead. The keyword tells you how many columns to use, and in what order to read them. Columnar transposition was widely used by hand, and it is the second half of the ADFGVX cipher, a German cipher from World War I that you’ll meet later in the book.
Enciphering¶
For example, encipher a rose by any other name would smell as sweet with the keyword FLOWER. The keyword has 6 letters, so the grid has 6 columns. In alphabetical order the keyword letters are E, F, L, O, R, W, so the E column is read first and the W column is read last.
keyword: F L O W E R
order: 2 3 4 6 1 5
------------
A R O S E B
Y A N Y O T
H E R N A M
E W O U L D
S M E L L A
S S W E E TReading the columns in order gives EOALLE (column E), AYHESS (F), RAEWMS (L), ONROEW (O), BTMDAT (R) and SYNULE (W):
ciphertext: EOALL EAYHE SSRAE WMSON ROEWB TMDAT SYNUL EWhen the message doesn’t fill the last row, some columns are one letter shorter than others. Here is the transposition step from the example on the ADFGVX cipher page, using the keyword TIME on the 18 letters FXDVVAFDAFFGVDXVDX (these letters come from the first step of the ADFGVX cipher; here we only do the transposition):
keyword: T I M E
order: 4 2 3 1
-------
F X D V
V A F D
A F F G
V D X V
D XThe T and I columns have 5 letters, and the M and E columns have 4. Reading E, I, M, T gives VDGV, XAFDX, DFFX and FVAVD, so the ciphertext is VDGVX AFDXD FFXFV AVD.
Choose a keyword with no repeated letters, so that the column order is clear. (If a letter does repeat, the usual rule is to number the copies from left to right.)
Solution to Exercise 1
SENDMORESUPPLIESBYFRIDAY has 24 letters, so the 4 columns each hold 6 letters. Reading the columns in the order A, C, M, P gives EOUIYD, SMSLBI, NRPEFA and DEPSRY, so the ciphertext is EOUIY DSMSL BINRP EFADE PSRY.
Deciphering¶
The recipient knows the keyword, so they know how many columns there are. The tricky part is knowing how many letters go in each column before writing them in.
If is a multiple of , every column has the same length. For example, a 28-letter ciphertext with the 7-letter keyword PRIVACY fills exactly 4 rows.
Here is an example with a short last row. Decipher TTBAL MHRFU MEEAT NEALR ECETI YRH with the keyword NOVEL. There are 28 letters and 5 columns, and . So every column has at least 5 letters, and the first 3 columns (N, O and V) have 6. In alphabetical order the columns are E, L, N, O, V, so the ciphertext splits into TTBAL (5 letters, column E), MHRFU (5, L), MEEATN (6, N), EALREC (6, O) and ETIYRH (6, V):
keyword: N O V E L
order: 3 4 5 1 2
---------
M E E T M
E A T T H
E L I B R
A R Y A F
T E R L U
N C HReading the rows gives meetmeatthelibraryafterlunch: “meet me at the library after lunch”.
Solution to Exercise 2
There are 17 letters and 4 columns, and . So the first column, W, has 5 letters and the others have 4. In alphabetical order the columns are G, I, N, W, so the pieces are EELE (G), HGAN (I), ELSD (N) and TAHAD (W). Reading the rows gives theeaglehaslanded: “the eagle has landed”.
How many keys?¶
Only the alphabetical order of the keyword’s letters matters. Any two keywords whose letters come in the same order produce the same ciphertext. So with columns there are different keys: for a 3-letter keyword, and for a 6-letter keyword like FLOWER.
An eavesdropper who doesn’t know the keyword length can try every length from 2 to 10 and every order for each one. That is possibilities: far too many to try by hand, but nothing for a computer. A longer keyword gives more keys, but each column gets shorter. In the extreme, a keyword as long as the message puts one letter in each column, and the cipher just shuffles the letters in the keyword’s order.
Like every transposition cipher, columnar transposition leaves the letter frequencies unchanged. Cryptanalysts also have a better attack than trying every order: they cut the ciphertext into columns and slide them next to each other, looking for common letter pairs such as TH and HE. That is one reason the ADFGVX cipher combines columnar transposition with a substitution step.