# Turingery

Turingery[1] or Turing's Method[2] (playfully dubbed Turingismus by Peter Ericsson, Peter Hilton and Donald Michie[3]) was a hand codebreaking method devised in July 1942[4] by the mathematician and cryptanalyst Alan Turing at the British Government Code and Cypher School at Bletchley Park during World War II.[5][6] It was for use in Cryptanalysis of the Lorenz cipher produced by the SZ40 and SZ42 teleprinter rotor stream cipher machines, one of the Germans' Geheimschreiber (secret writer) machines. The British codenamed non-Morse traffic "Fish", and that from this machine "Tunny".

Reading a Tunny message required firstly that the logical structure of the system was known, secondly that the periodically changed pattern of active cams on the wheels was derived, and thirdly that the starting positions of the scrambler wheels for this message—the message key—was established.[7] The logical structure of Tunny had been worked out by William Tutte and colleagues[8] over several months ending in January 1942.[9] Deriving the message key was called "setting" at Bletchley Park, but it was the derivation of the cam patterns—which was known as "wheel breaking"—that was the target of Turingery.

German operator errors in transmitting more than one message with the same key, producing a "depth", allowed the derivation of that key. Turingery was applied to such a key stream to derive the cam settings.[10]

## The SZ40 and SZ42

{{#invoke:main|main}} The logical functioning of the Tunny system was worked out well before the Bletchley Park cryptanalysts saw one of the machines—which only happened in 1945, shortly before the allied victory in Europe.[11]

The Lorenz SZ machines had 12 wheels each with a different number of cams (or "pins").

The SZ machines were 12-wheel rotor cipher machines which implemented a Vernam stream cipher. They were attached in-line to standard Lorenz teleprinters. The message characters were encoded in the 5-bit International Telegraphy Alphabet No. 2 (ITA2). The output ciphertext characters were generated by combining a pseudorandom character-by-character key stream with the input characters using the "exclusive or (XOR)" function (symbolised by  ).

Plaintext Key = Ciphertext

Similarly, for deciphering, the ciphertext was combined with the same key to give the plaintext.

Ciphertext Key = Plaintext

This produces the essential reciprocity to allow the same machine with the same settings to be used for both enciphering and deciphering.

Each of the five bits of the key for each character was generated by the relevant wheels in two parts of the machine. These were termed the chi (${\displaystyle \chi }$) wheels, and the psi (${\displaystyle \psi }$) wheels. The chi wheels all moved on one position for each character. The psi wheels also all moved together, but not after each character. Their movement was controlled by the two mu (${\displaystyle \mu }$) or "motor" wheels.[13]

The key stream generated by the SZ machines thus had a chi component and a psi component that were combined together with the XOR function. So, the key that was combined with the plaintext for enciphering—or with the ciphertext for deciphering—can be represented as follows.[13]

Key = Chi-Key Psi-Key

Symbolically:

K = ${\displaystyle \chi }$ ${\displaystyle \psi }$

The twelve wheels each had a series of cams (or "pins") around them. These cams could be set in a raised or lowered position. In the raised position they generated a "mark" ' x ' (1 in binary), in the lowered position they generated a "space" ' ' (0 in binary). The number of cams on each wheel equalled the number of impulses needed to cause them to complete a full rotation. It should be noted that these numbers are all co-prime with each other, giving the longest possible time before the pattern repeated. With a total of 501 cams this equals 2501 which is approximately 10151, an astronomically large number.[14] However, if the five impulses are considered independently, the numbers are much more manageable. The product of the rotation period of any pair of chi wheels gives numbers between 41×31=1271 and 26×23=598.

## Differencing

Cryptanalysis often involves finding patterns of some sort that provide a way into eliminating a range of key possibilities. At Bletchley Park the XOR combination of the values of two adjacent letters in the key or the ciphertext was called the difference (symbolised by the Greek letter delta 'Δ') because XOR is the same as modulo 2 subtraction (without "borrow")—and, incidentally, modulo 2 addition (without "carry"). So, for the characters in the key(K), the difference ΔK was obtained as follows, where underline indicates the succeeding character:

ΔK = K K

Similarly with the plaintext, the ciphertext and the two components of the key. Also, the relationship amongst them applies when they are differenced. For example, as well as:

K = ${\displaystyle \chi }$ ${\displaystyle \psi }$

It is the case that:

ΔK = Δ${\displaystyle \chi }$ Δ${\displaystyle \psi }$

If the plaintext is represented by P and the cipertext by Z, the following also hold true:

ΔZ = ΔP Δ${\displaystyle \chi }$ Δ${\displaystyle \psi }$

And:

ΔP = ΔZ Δ${\displaystyle \chi }$ Δ${\displaystyle \psi }$

The reason that differencing provided a way into Tunny, was that although the frequency distribution of characters in the ciphertext could not be distinguished from a random stream, the same was not true for a version of the ciphertext from which the chi element of the key had been removed. This is because, where the plaintext contained a repeated character and the psi wheels did not move on, the differenced psi character (Δ${\displaystyle \psi }$) would be the null character (••••• or 00000), or, in Bletchley Park terminology, '/ '. When XOR-ed with any character, this null character has no effect, so in these circumstances, Δ${\displaystyle \chi }$ = ΔK. Repeated characters in the plaintext were more frequent both because of the characteristics of German (EE, TT, LL and SS are relatively common),[15] and because telegraphists frequently repeated the figures-shift and letters-shift characters[16] as their loss in an ordinary telegraph message could lead to gibberish.[17]

To quote the General Report on Tunny:

Turingery introduced the principle that the key differenced at one, now called ΔΚ, could yield information unobtainable from ordinary key. This Δ principle was to be the fundamental basis of nearly all statistical methods of wheel-breaking and setting.[1]

### Bit-level differencing

As well as applying differencing to the full 5-bit characters of the ITA2 code, it was also applied to the individual impulses (bits). So, for the first impulse, that was enciphered by wheels ${\displaystyle \chi }$1 and ${\displaystyle \psi }$1, differenced at one:

ΔK1 = K1 K1 <>

And for the second impulse:

ΔK2 = K2 K2

And so on.

It is also worth noting that the periodicity of the chi and psi wheels for each impulse (41 and 43 respectively for the first one) is reflected in its pattern of ΔK. However, given that the psi wheels did not advance for every input character, as did the chi wheels, it was not simply a repetition of the pattern every 41 × 43 = 1763 characters for ΔK1, but a more complex sequence.

## Turing's method

In July 1942 Turing spent a few weeks in the Research Section.[18] He had become interested in the problem of breaking Tunny from the keys that had been obtained from depths.[3] In July, he developed the method of deriving the cam settings from a length of key.[1] It involved an iterative, almost trial-and-error, process. It relied on the fact that when the differenced psi character is the null character (••••• or 00000), /, then XOR-ing this with any other character does not change it. Thus the delta key character gives the character of the five chi wheels (i.e. Δ${\displaystyle \chi }$ = ΔK).

Given that the delta psi character was the null character half of the time on average, an assumption that ΔK = Δ${\displaystyle \chi }$ had a 50% chance of being correct. The process started by treating a particular ΔK character as being the Δ${\displaystyle \chi }$ for that position. The resulting putative bit pattern of x and for each chi wheel, was recorded on a sheet of paper that contained as many columns as there were characters in the key, and five rows representing the five impulses of the Δ${\displaystyle \chi }$. Given the knowledge from Tutte's work, of the periodicity of each of the wheels, this allowed the propagation of these values at the appropriate positions in the rest of the key.

A set of five sheets, one for each of the chi wheels, was also prepared. These contained a set of columns corresponding in number to the cams for the appropriate chi wheel, and were referred to as a 'cage'. So the ${\displaystyle \chi }$3 cage had 29 such columns.[19] Successive 'guesses' of Δ${\displaystyle \chi }$ values then produced further putative cam state values. These might either agree or disagree with previous assumptions, and a count of agreements and disagreements was made on these sheets. Where disagreements substantially outweighed agreements, the assumption was made that the Δ${\displaystyle \psi }$ character was not the null character /, so the relevant assumption was discounted. Progressively, all the cam settings of the chi wheels were deduced, and from them the psi and motor wheel cam settings.

As experience of the method developed, improvements were made that allowed it to be used with much shorter lengths of key than the original 500 or so characters.[1]

## References and Notes

1. Template:Harvnb in Testery Methods 1942-1944
2. Template:Harvnb
3. Template:Harvnb
4. Template:Harvnb in Early Hand Methods
5. Template:Harvnb
6. Template:Harvnb
7. Template:Harvnb
8. Template:Harvnb
9. Template:Harvnb
10. Template:Harvnb
11. {{#invoke:citation/CS1|citation |CitationClass=citation }}
12. Template:Harvnb in German Tunny
13. Template:Harvnb in German Tunny
14. Template:Harvnb
15. {{#invoke:citation/CS1|citation |CitationClass=citation }}
16. Newman c. 1944 p. 387
17. Template:Harvnb
18. Template:Harvnb
19. Template:Harvnb which reproduces a ${\displaystyle \chi }$3 cage from the General Report on Tunny

## Bibliography

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }} That version is a facsimile copy, but there is a transcript of much of this document in '.pdf' format at: {{#invoke:citation/CS1|citation |CitationClass=citation }}, and a web transcript of Part 1 at: {{#invoke:citation/CS1|citation |CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }}

• {{#invoke:citation/CS1|citation

|CitationClass=citation }} Transcript of a lecture given by Prof. Tutte at the University of Waterloo