Hi r/AskHistorians! I just saw the Imitation Game for the first time, so I was reading up on how the Enigma Machine worked. The article said that a message could only be decoded by the receiver if their machine was set to the same settings as the sender. So how did they manage this? Thanks in advance!
The key was actually sent as part of the message. After 1938, a three letter code was selected by the sender and transmitted as "plaintext" (unencrypted) at the beginning of the message. This code was used to encrypt the actual message key, which came next, followed by the message itself, encrypted using the message key. This allowed the receiver to instantly know which setting to use. Prior to that, there were global codes called "Grundstellung," found in codebooks, that changed based off of the day or various other conditions. The operator would select an actual code, encrypt that using the Grundstellung, put it at the beginning of the message, and then encrypt the rest of the message using their code. The receiver could then look up the correct Grundstellung in their identical codebook, decrypt the transmitter's selected code, and decrypt the rest of the message.
This may go without saying, but each Enigma machine in use by a certain branch of the military at a certain time was identical, so once the code was known, the settings just had to be dialed in on the machine's rotors and the message decrypted.
source, which contains a lot more detailed information about the machines themselves. They're pretty neat.
EDIT: I explained something poorly and corrected it.
As /u/Stoyon says, there were several elements of an Enigma machine that had to be configured:
[The components of the Enigma machine] (http://www.codesandciphers.org.uk/enigma/enigma2.htm)
There were five rotors or wheels (for the Army and Air Force, eight for the navy) from which three could be used, in any order. Each rotor also had a ring that could be rotated to 26 possible settings. Most variants had a plug board on the front of the machine, the Steckerbrett, that performed additional scrambling.
The settings for these elements were distributed to units in printed form by courier, typically with a month's worth of daily settings on a sheet. Stoyon's excellent [link] (http://users.telenet.be/d.rijmenants/en/enigmaproc.htm) contains several examples such as [an Army sheet from October 1944] (http://users.telenet.be/d.rijmenants/pics/hires-wehrmachtkey-stab.jpg) listing, from the left: the day of the month; the three rotors to use (roman numerals) and their order; the ring settings for the rotor; the letters to connect on the plug board. The last section, the Kenngrupen, was used at the beginning of the message to indicate which key the message was encoded in (different units used different keys, so there wasn't a single set of settings for all Enigma machines everywhere).
To avoid all traffic on a particular key being enciphered using exactly the same settings, the operator then selected a random start position for the three rotors, encoded that according to the daily settings, and transmitted it at the start of the message. Until 1940 the start position was transmitted twice; this cryptographic weakness was one of the ways that Polish codebreakers were able to crack the Enigma.
Naval vessels had to carry settings for as long as their voyage was expected to last, and Naval Enigma used a more complex method for indicators including bigram substitution.
The websites linked ( http://users.telenet.be/d.rijmenants/index.htm and http://www.codesandciphers.org.uk/ ) have a wealth of information, and the procedure is also described in e.g. Codebreakers (ed. Hinsley & Stripp) and David Kahn's Seizing the Enigma.
One of my favorite YouTube channels, Numberphile, has a really good video on the Enigma Machine. It shows how they were operated and configured, and if you watch the second one, describes how Turing was able to crack the code with the power of math!
Books. Code books, which had to be generated in advance and distributed to all the units in a network that were to receive encrypted messages.
Here you can find code books for three rotor machines. They will allow you to communicate with Enigma World Code Group members. http://enigmaworldcodegroup.freeforums.net/thread/55/optional-2016-ewcg-codebook
Once you have the code books, follow the procedures listed below to create your own message http://enigmaworldcodegroup.freeforums.net/post/185
While the code books tell you how to set up the machine, a message key is still needed. If the outer wheels are set to AAA, the phrases "The wheater is fine" and "The wheather is cold" will encrypt to the same result except for the last four letters. By modifying the initial position of the wheels, the two phrases will encrypt to different results. The receiver has no idea what your initial wheel setting was, that is why it has to be sent at the beginning of the message.
Thus, in the end the security of the system depends on keeping the daily machine settings secret.