*As long ago as the Ancient Greeks, warring armies have encrypted their communications in an attempt to keep their battle plans a secret from their enemies. However, just as one side invented an ingenious new way to encipher its messages, so would its enemies discover a clever way of cracking that code. The result has been that codes and ciphers have become more and more complex and
increasingly difficult to crack over time, as, throughout history, an intellectual battle has raged between code makers and code breakers.*

*The battle of wits was never keener than during the Second World War, when the Germans used the famous Enigma machine - which they believed uncrackable - to encode messages, and the Allies worked at Bletchley Park to decipher the code.*

## The birth of an enigma

German soldiers using an Enigma machine during the second world war

Up till the Second World War, the most advanced forms of encryption involved simple paper and pencil techniques. But security blunders on both sides during the First World War highlighted a need for a higher level of secrecy, with more advanced methods of enciphering messages. Both the Allies and the Axis countries were looking for a new way to encrypt messages - a way that would result in complete security. (For more information, have a look at our explanation of the basic terminology of codes and ciphers.)

In 1915 two Dutch Naval officers had invented a machine to encrypt messages. This encryption tool became one of the most notorious of all time: the Enigma cipher machine. Arthur Scherbius, a German businessman, patented the Enigma in 1918 and began selling it commercially to banks and businesses.

The Enigma machine's place in history was secured in 1924 when the German armed forces began using a specially adapted military version to encrypt their communications. They continued to rely on the machine throughout the Second World War, believing it to be absolutely unbreakable.

## How the Enigma machine worked

A diagrammatic representation of an Enigma machine

When a plaintext letter was typed on the keyboard, an electric current would pass through the different scrambling elements of the machine and light up a ciphertext letter on the "lamp board". What made the Enigma machine so special was the fact that every time a letter was pressed, the movable parts of the machine would change position so that the next time the same letter was pressed, it would most likely be enciphered as something different. This meant that it wasn't possible to use traditional methods to try and crack the notorious cipher.

To make things even more difficult, different parts of the machine could be set up in different ways, with each setting producing a unique stream of enciphered letters. Unless you knew the exact settings of the machine, you couldn't decipher the messages.

## How many ways are there to set up an Enigma Machine?

### Choosing Rotors

An Enigma machine rotor. Copyright Simon Singh

Army issue Enigma machines had three revolving "wheels" or "rotors" that could be taken out and changed about.The first task for an Enigma operator would be to decide which rotor went in which position. There were five rotors to choose from and they could be inserted into three positions on the Enigma machine.

**Question 1**: How many possible ways are there of positioning 5 rotors in 3 slots in the Enigma? (Check your answer.)

### The rotor starting positions

**Question 2**: Once you have chosen the order of the rotors, how many possible ways can you set the starting positions of the rotors?

(Check your answer.)

### The ring settings

Every time a letter was pressed on the keyboard, the rotor on the far right would move around one place. Once it had completed a full revolution (ie moved forward 26 places), it would kick the middle rotor forward one position. When it had completed another revolution, it would again kick the middle rotor forward one position. When the middle rotor had completed a full revolution, it would kick the left-hand rotor forward.

The point at which the right hand rotor kicked the middle rotor forward and the point at which the middle rotor kicked the left hand rotor forward could be changed. This was called the "Ring Setting".

**Question 3**: How many possible "Ring settings" were there on a 3-rotor army Enigma?

(Check your answer.)

### The plugboard

A diagrammatic representation of the plugboard

On the front of the machine was another section called the "plugboard". The Enigma machine had several cables with a plug at each end that could be used to plug pairs of letters together. If A were plugged to B then, on typing the letter A, the electric current would follow the path that was normally associated with the letter B, and vice versa.

Enigma machines had 10 cables with which to link up pairs of letters.

**Question 4**: How many ways are there to link up pairs of letters on the Enigma machine?

The answer is that there are approximately 150,000,000,000,000 - that is, 150 million million - possible combinations of 10 pairs of 26 letters on the plug board. The maths behind this calculation is complex, but a full explanation is given here, a page from Tony Sale's website.

Therefore, the total number of possible ways in which a standard army-issue Enigma machine could be set up was:

## Deciphering Enigma

When the Enigma machine is used, the Enigma machine itself is the algorithm; the way in which it is set up is the key. Just as with any other type of cipher, as long as the recipient knows the key, the process of deciphering an Enigma encrypted message is incredibly simple. A German soldier receiving an enciphered message simply had to type the ciphertext letters into his own Enigma machine. If his machine was set up exactly in exactly the same way as the message sender's, then the plaintext letters would appear on the lamp board.

However, just as with any other type of cipher system, if you don't know the key it is very difficult to read the message - even if you know which system was used to encipher it.

The British had set up listening stations (called *Y Stations*) all over Britain, so that they could eavesdrop on the German military. Even though the Allies had managed to get hold of Enigma machines, in order to decrypt the messages they intercepted they needed to know the key To make it as difficult as possible for the Allies to decipher messages, the Germans would change the key every
day, resetting their Enigma machines at midnight every night.

### Agreeing on a key

A monthly keysheet

Cipher machine operators were issued with a Key Sheet every month, which told them how to set up their Enigma machines for every day that month. There was an obvious security flaw: if the Allies recovered a key sheet, they would be able to read the Enigma messages.

For this reason, Key Sheets were extremely closely guarded and were printed in soluble ink. If it ever looked as though a Key Sheet might be captured by the Allies, German soldiers would dip it in water and wash off all the information.

The Germans believed the strength of the Enigma lay in the fact that it was impossible to work out the key from the billions and billions of potential keys every single day. As long as the Allies did not get hold of the key sheet, their communications would remain secure.

### The work at Bletchley Park

Bletchley Park. Copyright Bletchley Park Trust

In August 1939 the British established the Government Code and Cipher School at Bletchley Park in Buckinghamshire. The people recruited to work there came from a variety of backgrounds. There were experienced codebreakers, secret service officers, mathematicians, scientists, crossword experts, international chess players, students, actresses and even astrologers and debutants.

Fortunately for the British codebreakers, in the years running up to the war Poland had worked on various techniques for cracking Enigma. Shortly before the German invasion of Poland, they shared their work with their British allies. Poland's government was the first to employ mathematicians as code-breakers, and the mathematicians' logical minds proved to be just what was needed to tackle Enigma.

This vital headstart from the Polish, coupled with the unique problem-solving and intuitive thinking skills of Bletchley's recruits, meant that Enigma was cracked in early 1940 a reliable technique for cracking Enigma was established. The British code breakers worked in shifts around the clock for the whole of the war, using paper and pencil as well as newly invented mechanical techniques to work out the particular Enigma machine settings for each and every single day.

Unwittingly, the Germans themselves helped the British to decipher the Enigma. For example:

- Messages often began with the same opening text - many began with the word
*Spruchnummer*(Message Number), and many Air Force messages began with the phrase*An die Gruppe*(To the Group). - Messages often enciphered routine information such as weather reports and phrases such as
*Keinebesondere Ereignisse*(Nothing to report). - Messages often ended with
*Heil Hitler*! - The Germans often transmitted the same message more than once, with each version enciphered differently.

These lapses provided the codebreakers with clues, called *cribs*, about how the Enigma machines had been set up on that day. These cribs were essential for breaking the ciphers. For example, without a crib it would still take several months today to decipher an A4 page of ciphertext using a modern PC with trial and error methods.

However, the cribs alone were not enough. The codebreakers at Bletchley Park developed new procedures and algorithms for determining the set-up of the Enigma and also had to develop electronic computing devices to implement these methods.

Today, historians believe that the work of the code breakers at Bletchley Park shortened the war by two years.

### Neglected heroes

Among the most famous of the leading code breakers at Bletchley Park was a mathematician from the University of Cambridge, Alan Turing. Turing was regarded by many as a genius. He played a leading role in breaking the more complicated Naval Enigma cipher (codenamed Shark) and also established the principles behind the modern computer.

Despite their remarkable work, however, for a long time afterwards none of the second world war code breakers received the public recognition they deserved. In order to preserve British security, the breaking of Enigma remained a tightly guarded secret for the duration of the war, and for the following 30 years. The people who had worked at Bletchley Park were forbidden from talking about what they had done and as a result their contribution to the war effort was entirely forgotten. However, over the past 30 years more and more information has been released about the incredible story of Bletchley Park.

Tragically, for some, however, the acknowledgments have come too late. Alan Turing committed suicide before he was ever publicly recognised for his extraordinary part in the war and before his contributions to the science of codes and code breaking were fully understood.

The British Government still operates a code breaking department, at "Government Communication Headquarters" in Cheltenham. And to this day they rely on mathematicians for their problem solving abilities and logical thinking: GCHQ boasts the highest concentration of pure mathematicians in the country. Today's secret codes are much more sophisticated than the Enigma cipher and their strength relies on the inability to factorise large numbers, so with today's worries about global terrorism, the role of our code breakers is just as vital as during the second world war.

## More information

- The Enigma Project:

The MMP's outreach project which takes codes, code breaking and a genuine WW2 Enigma machine into the classroom. - Bletchley Park:

Find out about WW2's code breaking heroes and information on breaking Enigma. Bletchley Park is now a museum and information about visiting can also be found on their website. - NRICH Maths:

The March 2004 issue (select this on the left hand menu) is all about different secret codes with puzzles to break. - National Cryptologic Museum:

The US National Security Agency's museum of cryptography. - Simon Singh's Crypto Corner:

Information about a host of different codes. The story of the Code Book Cipher Challenge, who won it and how. Also links to other cryptography websites. Follow links to the Black Chamber for on-line puzzles and decryption tools. You can also download free copies of the Code Book CD-ROM. - Alan Turing Memorial:

Information about Alan Turing's memorial statue in Manchester. - Codes and Ciphers:

All you ever wanted to know about Second World War codes and ciphers.

## Answers to the questions in the text

### Answer 1

For the first slot, you can choose any one of 5 rotors. For the second, you can choose any one of 4 rotors. For the last, you can choose any one of 3 rotors. So there are

Back to question 1.

### Answer 2

As there are 26 letters of the alphabet, each of the 3 rotors could be set in any one of 26 different starting positions. This gives a total of

Back to question 2.

### Answer 3

The first ring can be set in any of 26 positions, as can the second, so there are

Back to question 3.

## About the author

Claire Ellis has recently joined the Millennium Mathematics Project, the Cambridge-based mathematics enrichment and dissemination group that publishes *Plus* magazine. She runs the Enigma Project.

## Comments

## I don't get the calculation.

If you multiply the numbers: 17.576 x 60 x 676 x 150.738.274.937.250, you doesn't end up with 158 million million million or something near. You end up with: 107.458.687.327.250.619.360.000. How come it says here, that the calculations result is approx 158 million million million?

## You dont include the "676"

Because the 676 is part of the 17,576, it isn't directly relevant in the final equation because you have already considered it, when you do: 17567*60*1.5*10^14 you get an answer of around 1.58*10^20

## 676 Factor

If the 676 factor is already considered, exactly how do the ring settings alter the overall number? There are 17,576 possible starting positions.

## You don't actually take into

You don't actually take into account the 676 notch positions. They don't affect the number of permutations in the machine.

## Notch settings should be included in the key length

Ignoring the 676 factor of the notch settings ignores the fact that the notches changes the rotor setting at some point in the message. So the 17,576 rotor settings can change after the first character of the message and must change by the 26th character. These changes are additions to the key length, when viewed over the entire message. That means that for a message length of 1 character, the key length is indeed 1.58 X 10^20, but for a real message longer than 1 character, the key length would be 1.07 X 10^23. The fact that the movement of the rotors is regular (like an odometer) makes the cryptoanalysis easier but does not reduce the factor of 676.

## Total settings

Each of 5 rotors may be chosen for the 3 rotor slots. Each rotor creates a permutation of the code. They would have been smart not to have any of the 5 rotor permutations be commlutable with any other, so for choices for first 3 slots one gets (all in agreement with this web site):

5*4*3=5!/2!=60.

Then obvious settings of the 26 position rotors:

26*26*26=26^3=17576.

Now plug board: Apparently from pictures they didn't use jumpers blocks, so the plugs must indeed have internal switches so that a position without a plug shorts through from output to input. Each cable enacts a swap, but all the 10 cables are identical. Likewise swapping ends of the cables produces an identical results.

26*25/2 * 24*23/2 * 22*21/2 * ... * 10*9/2 * 8*7/2 / 10! =

(26!/6!)/(10!*2^10) = 158.962555217826 million million million ish, call it "159" like in the movie! (PS: Not one scene of The Imitation Game came from the book, not one thing actually happened. Still I think that the decoder wheels bore some vague relationship to the "bombs" construction and is useful for thought. Successive columns would be successive input/rotor positions, and rows correspond to rotors all tree searched. Needs more for searching the plugboard settings than was shown in the movie. At least I'm making some progress in understanding this now.)

Now the 26*26 additional ring settings are not "accounted for" in any other calculation. They do truly establish another multiplier of settins positions. HOWEVER the decoding will on average go 13 characters before a "notch" kicks the 2nd wheel over, so one could see if there was an appearance of a recognizable word most likely. Thus these don't have to be searched for as intently as a fractional word or phrase can lead to decoding the notch or ring positions later as the first breakpoint into unintelligibility. Thus leaving this out is just a convention.

Also note that there are actually more possible plug board settings because the code sheets can indicate that a cable is not used, so one actually has 10 cables, 9 cables, 8 cables, etc. They probably would not go too far down.

## enigma code breaking

We all know that the English invented everything but I read years ago that the Enigma code was first broken by a Polish person who passed it on to French intelligence who in turn passed it on to the English.

This detracts nothing from Turing;s achievements.

As an interesting aside, Turing had a colleague and they experimented with robots .

When this colleague retired he thought it would be interesting to look at the earlier models which were that simple anybody could build one.

But, he had no chance, all was classified.

## enigma code breaking

Certainly a credit should be given to Polish mathematicians who for the first time worked out the secret of Enigma. These were: Marian Rejewski, Jerzy Rozycki and Henryk Zygalski. In 1932 they already established inner rotors wiring which was probably one of the greatest break trough steps in decrypting messages. The also reconstructed prototype of Enigma itself and designed electromechanical machine called by them "Bomby" to find the keys to daily messages decryptions. Alan Turing did not design first computer. He worked on improved device the "Bomby" which later was further improved by American engineers. Polish Cypher Bureau team gave all the secrets about Enigma machine, the "Bomby" design and other related information to the British crypto-analysts already in July of 1939.

## Turing and robots

Modern robotics is a diverse subject.

Part is just mechanics, many industrial robots work without any "artificial intelligence" (AI) like programming. But others distinctly combine AI (which can be independent of any robotic mechanism) and the mechanisms, such as visual analylsis for feedback. These are all of course based upon the development of the general purpose computing devices--for which Turing did make significant early contributions. In later years those developing ideas for computers and Turing differed on approaches and computer developers ignored turing's later ideas, but they certainly were part of the original foundations.

All of that was from the unclassified path from Turing's work.

Interestingly, relating to code breaking, some of my work and others on search methods for puzzle solving in AI could have been independently discovered back then and built into the hard-wired code breaking machines that essentially implemented a tree search for settings to match message fragments.

## Error in Design of the Enigma Machine

It is widely agreed that the design of the rotor and wiring system in the enigma resulted in the not so irrelevant error that a letter could not be coded into itself and hence gave a great help in using cribs.

However I thought that the plugboard would eradicate most of this error or perhaps I do not understand it correctly.

As an example assume A is connected on the plugboard to B. Now we know that B will be coded to some letter other than B itself. I assume it could be coded to A and hence pressing key A would light up A.

I would love to know the answer to this.

Regards Trevor Weaver

trevor_weaver@talktalk.net

## Plugboard

When you connect B to A, you also connect A to B! Which means that if you enter A, your letter turns to B, and the letter that comes back can be anything but B; but the only way to get an A as a result is if the letter going through the plugboard is a B! Which means that by extension, you cannot get A in return.

## Don't Forget the 6 Unpaired Letters

Trevor,

According to this article, there are only 10 cords while there are 13 pairs of letters. That leaves 3 pairs or 6 letters whose positions haven't changed. If 'A' was one of those 6, pressing 'A' would indeed return 'A'.

## My Previous Post is Incorrect

I didn't fully understand how the Enigma machine worked when I made my last statement and still don't, but I understand it a little better now and realize that when a letter is typed, you definitely won't get the same letter back. The reflector (not mentioned in this article) makes sure of that.

## Pairs of letters in plugboard

OK, now I am thinking as an EE, about design of the plugboard. Clearly one of the pair designated for each letter is the output. And the other is the fed back input to the next part of the machine. This would match up to the exactly 26 pairs (52 total) jacks.

First, how could some of the jacks remain unconnected? If they remained unconnected, then their output side would go nowhere! It would not be left as its own code, it woud produce no code at all! Those banana jacks were not like our complex headphone jacks that have an inner switch--this is very simple hardware, appears to be nothing more than a plugboard of simple banana jacks in pairs.

(AND the logic requires that the jacks have outputs as well as inputs--otherwise how can they possibly map one letter to another at all--only by one letter's output mapping by a wire to another letter's input. Thus perfectly sensible 26 outputs, 26 inputs, exactly the 52 jacks on the board.)

Those look like ordinary banana jacks--I have many in my shop, a modern caryover from a bygone day. In fact they look like the paired banana jacks that I have many of, so paired cables could be used for ease of connection--just they constrain one end of the pair to go to the other end of the pair. And would of course swap--else connecting out to out, in to in, not working. Thus forming a swapping of the letter pair! Still could use 26 individual banana cables to map any letter to any letter.

This logic implies that there would be 26 wires total within all cables and jumper plugs as I wil discuss. (Not 10, not 13--though they could be paired cables for ease of connection in which case there are 13 double wire cables still equivalent to 26 wires just constrained in positions. There could even be 10 paired cables and 6 jumper plugs so 10 pairs swap letters as discussed, and then 6 jumpers mapped to the same letter--but this could also be generalized by 26 individual double-banana cables. Jumping the top row to the same letter's bottom row would map letter to itself.) The specifics could be a convention of how the cables were constructed as paired cables, and 10 paired cables and 6 jumper plugs would fill all positions and swap letters as discussed for exactly 10 pairs. If the "10" was derived from loosing 3 paired wires and there were no jumper plugs around, then the machine would not work! Is the "10" derived from coding sheet?

This might even make sense. The 6 jumper plugs used so that not all letters are remapped, thus NOT allowing codebreaking to assume no letter maps to itself. 10 paired cables to ease the operator connection method. (All reduced from the possability of any permutation mapping of 26 letters if 26 individual cables were provided.) 13 paired cables and no jumper cables would assure no character maps to itself, but allows any letter to be swapped with another and the next swap reduced by 2 recursively until all letters mapped.

Can't immediately figure a factorial notation, but 25*23*21*...*3*1 = 7.90585 * 10^12 ish combinations with 13 paired cables.

10 cables: 25*23*21*...*9*7=527.0569 * 10^9 ish combinations.

## mrherisson-crypto@yahoo.fr

Hi,

I find it unfair that although you are using his Enigma simulator as a "diagrammatic representation", you do not mention Dirk Rijmenants anywhere.

His site is a huge resource as far as encryption is concerned (not only Enigma)

http://users.telenet.be/d.rijmenants/

## Poland's overlooked Enigma codebreakers

The first breakthrough in the battle to crack Nazi Germany's Enigma code was made not in Bletchley Park but in Warsaw. The debt owed by British wartime codebreakers to their Polish colleagues was acknowledged this week at a quiet gathering of spy chiefs.

http://www.bbc.com/news/magazine-28167071

oo1@o2.pl

## Codebreakers of Poland

Thanks to your groundbreaking work the Allies ( Bletchley Park and other) were able to decode enigma transmissions - well done!

## Plugboard Mystery

I viewed Tony Sale's page to try to understand the math behind 150 million million permutations for the plugboard. His math was far too advanced for me, so I tried to approach it from a practical point of view.

With the first cord, I have 26 letters to choose from for one end, then (since a letter can't be plugged into itself) I have 25 letters to choose from for the other end. Since a letter can only be plugged into 1 other letter, that leaves 24 letters to choose from for the next cord.

Factoring 26 X 25 X 24 X ... X 7, my calculator showed the answer of approx. 5.6e23 or 56 thousand million million million, a number that's over 3.6 trillion times greater than the number that is reported in this article.

Is my calculator wrong or did Mr. Sale make a mistake? I genuinely would like to know, because I don't understand it.

## Plugboard Mystery

Consider the following simple case: six letters and two wires.

You can't just say 6 * 5 * 4 * 3, because that would consider "wire 1 connects A to B / wire 2 connects C to D" and "wire 1 connects C to D / wire 2 connects A to B" as distinct choices while they are actually the same.

## Plugboard

With the first cord, I have 26 letters to choose from for one end, then (since a letter can't be plugged into itself) I have 25 letters to choose from for the other end.

Comment: Correct, but you have to be careful because it doesn't matter which end of the cord is plugged in first, so the number of possibilities here is 26*25/2.

Since a letter can only be plugged into 1 other letter, that leaves 24 letters to choose from for the next cord.

Comment: Correct, so for the second cord there are 24*23/2 possibilities.

So you might think that the total number of possible ways to configure 2 cords would be 26*25*24*23/(2*2) but that is wrong. This is because it doesn't matter what order you put those two leads in. This is of fundamental importance in maths, and is the difference between a permutation and a combination.

A permutation refers to a way of selecting elements from a group where the order of selection matters. A good example of this is the number of ways of selecting 3 Enigma rotors from 5. This is a permutation because the order of selection matters, since each rotor position is different: you have a fast rotor, the middle rotor, and the slow rotor. So the answer is that there will be 5*4*3=60 ways. Mathematicians write this as 5P3 meaning how many ways can you select 3 objects from 5 when the order you select them matters.

A combination refers to the number of a way of selecting elements from a group where the order that you select them doesn't matter. For example, in the National Lottery it doesn't matter what order the balls come out, all you have to do is pick the right numbers irrespective of order. So if the numbers go from 1 - 50 and you have to pick 6 balls there will be 50*49*48*47*46*45 ways in which order matters, but you then have to divded by the number of ways you can order 6 balls, which is 6*5*4*3*2*1. Mathematicians call this 50C6 meaning the number of ways you can select 6 things from 50 where order of selection doesn't matter.

So, following this, and going back to the 2 cord problem, we need to divide by the number of ways we can select 2 cords, which will be 2.

Going to 3 cords, the number of ways we can put the cords into the plugboard will be 3*2*1 known as 3 factorial, written 3! The number of choices for the third cord will be 22*21/2. So for three cords we have:

26*25*24*23*22*21/((2*2*2)*3!)

4 cords will be 26*25*24*23*22*21*20*19/((2*2*2*2)*4!)

You should be able to see a pattern emerging now. If there are n cords then the number of the denominator will be n!*2^n. The number on the top will be 26*25*24*23 ... until you have 2n numbers. Note that this can also be written as 26!/(26-2n)! Try out a few values of n to convince yourself.

So this gives the final formula for n cords as 26!/((26-2n)!*n!*2^n)

If you put n=10 you will get the 150 milliion million answer. Interestingly, if you put n=11 you get a bigger answer still, but for n=12 and n=13 the number falls. So the Germans missed a trick, they should have used 11 and not 10 cords !

## Pairs of letters in plugboard (Error correct from wherever)

Somewhere I put in a set of notes, and at the end did calculation. Viewing the coding sheet, clearly they used 10 cables with pairs of banana plugs at each end, and wires were swapped so that up to 10 pairs could be swapped. However they show entries in the coding sheet of "*" which I assume means no cable used--thus a jumper. In all places where a cable is not used, a jumper plug must have been used to map the output to itself. The "10" clearly comes from the coding sheet. I did the math wrong wherever my post appears.

This time, assume no "*" entries so all combinations from 10 cables are used. You don't count the remaining slots as combinations--they are algorithmically determined as jumper blocks to themselves so no choices! Since pairs swap and first choice is 26 starts to 25 remaining but swapping is equivalent, this means divide by 2.

Thus: 26*25 * 24*23 * ... * 10*9 * 8*7 / 2 = 26!/(6!*2) = 280.0635 * 10^21 ish.

## Pairs of letters in plugboard (Error correct from just last)

Wish I could see my entries and edit.

Seeing missing divisions by 2, factors with 10 pair cables, rest jumper blocks:

26*25/2 * 24*23/2 * 22*21/2 * ... * 10*9/2 * 8*7/2 = 26!/(6! * 2^10) = 546.999 * 10^18 ish.

## Rotor: Choosing & Positioning

There are 2 things:

1. Choosing the rotors: Say choosing 3 from 5 rotors. That will be 5*4*3 or 5C3.

2. Positioning the rotors: Once we have chosen the rotors, they can be permuted. 3 rotors would be 3! i.e. 6 different ways.