The Enigma machine was an advanced electro-mechanical cipher machine developed in Germany after World War 1. The Enigma machine was used by all branches of the German military as their main device for secure wireless communications until the end of World War 2. Several types of the Enigma machine were developed before and during World War 2, each more complex and harder to code break than its predecessors. The most complex Enigma type was used by the German Navy. In addition to the complexity of the Enigma machine itself, its operating procedures became increasingly complex, as the German military wanted to make Enigma communications harder to code break.
Various intelligence evidence during World War 2 led the German military to make several investigations about the possibility that The Allies can read Enigma messages. The German intelligence and communications experts concluded that Enigma was still secure from allied code breakers. They were wrong.
The basic operating procedure of the Enigma machine was simple. To send an encrypted message, the operator set the Enigma's electric and mechanical settings (the plug wirings and the rotor wheels) to a predefined initial combination known to him and to the receiving operator. Then he typed the free text message on the Enigma's keyboard. For each typed letter, a different letter was lit in the upper board. The operator wrote down each lit letter, so that when he finished typing the original message on the Enigma, he had a meaningless stream of letters, which was the Enigma-encrypted message. He then transmitted the encrypted message with a standard Morse code radio transmitter. The receiving operator wrote the received encrypted message, set his Enigma machine to the same pre-defined combination, and then typed the message at the machine's keyboard. Typing the encrypted message on his Enigma machine with the same combination of settings deciphered it, so that the operator read the original free text message by the letters lit in the upper board as he typed.
In the age before digital electronics and computers, code breaking the ciphered messages produced by the Enigma machine was almost impossible even if the code breaker had a working copy of the Enigma machine, as long as he didn't know the right combination of initial electric and mechanical settings, which were also periodically changed. Additional security procedures such as double encryption and using codes in the original free text message made it even harder to code break an Enigma message, so no wonder the German experts were over confident about the security of the Enigma machine despite the suspicions raised during the war.
Tremendous and continuous efforts were required to code break the German Enigma machine, to be able to continue to do so despite German improvements, and to do so fast enough before the achieved information was too old to be useful. The improvements made by the Germans several times before and during the war, both to the Enigma machine and to its operating procedures, enhanced Enigma security and made it harder to code break. Some of these changes caused "darkness" periods which lasted for months, in which the German Enigma messages could not be deciphered. The longest "darkness" period was with the German Navy's Enigma machine, which could not be deciphered for four years between 1937-1941, and remained the most difficult to code break of all German Enigma networks (army, Luftwaffe, etc), because the German Navy used the most advanced Enigma machine type, and used it with the most secure operating procedures.
The great efforts to code break the Enigma required the combined efforts and talents of brilliant mathematicians, code breakers, intelligence officers, and communications experts, deeply familiar with German language and mentality and with radio operator mentality and procedures. It also required daring and skillful combat operations, mainly at sea, some carefully planned and some exploiting rare opportunities. The Enigma code breakers also used an increasing number of machines, nicknamed "Bombe", which provided electro-mechanical computing power which helped them significantly shorten the process of deciphering the Enigma messages.
The first British "Bombe" machine was designed by Alan Turing, a genius mathematician which developed the theoretical model of the computer, and served during World War 2 as a senior code breaker at the British code breaking center at Bletchley Park. The advanced British "Bombe", was derived from the pre-war Polish "Bombe" (bombs) machine, developed by Polish code breakers who slowly deciphered pre-war early type Enigma messages in 1933-1938.
An additional security effort was needed, not just to keep the secret from the German intelligence despite an increasing number of various witnesses, but to also carefully balance between the desire to use the information achieved from reading German Enigma messages, and the constant risk that the results of combat operations based on that information will lead the German intelligence to conclude that The Allies read their Enigma machine messages. Many thousands of lives were at stake at either side of this delicate balance.
Overall, it is estimated that the success of the efforts to code break the German Enigma machine helped The Allies defeat Nazi Germany two years earlier than they would without it, saving countless lives, and making it one of the most successful intelligence operations in history. It it also important to note that German code breakers could read a significant part of the coded messages transmitted by The Allies.
The first step, which started the effort to code break the German Enigma machine, was the result of treason in the German side. Hans Schmidt, a clerk in the German government codes department who got his job thanks to his brother which was a senior military commander, lived complicated personal life which led him to contact the French intelligence in 1931 and offer to sell them top secret documents for money. Schmidt gave the French intelligence not just the Enigma machine's operating manual, but also settings lists. The French and British code breakers at those early pre-war years, which received this intelligence treasure, could not decipher the Enigma even with it, so they shared it with the Polish code breakers. The Polish code breakers realized that even with the available documentation of the German Enigma machine, the only way to ever decipher Enigma messages is to build an Enigma-like machine, which would help them decipher it, and unlike the British and French code breakers, they do so in 1932.
With their Enigma-like machine, built thanks to the German documents they received from the French, and later with a more advanced machine they nicknamed "Bombe", the Polish code breakers successfully deciphered German Enigma messages for over six years until 1938, and they did not tell the French anything about it...
As part of the German military preparations for war, the Germans made several technical enhancements to the Enigma machine which made it much harder to code break. The Polish code breakers struggled with the new challenges by themselves for over a year, with some success, but eventually they decided to share all they knew with the French and British code breakers. They did so just one month before Hitler's invasion of Poland. It was much too late to save Poland from Adolf Hitler, but the Enigma machine code breaking knowledge provided by the Polish code breakers was extremely important. It is estimated that without the Polish knowledge, learned in over six years of code breaking, the British code breakers could not efficiently decipher the Enigma before 1942.
By mid 1940, thanks to the Polish knowledge and the first type of the British "Bombe" machine designed by Alan Turing, the British code breakers at Bletchley Park could read some German army Enigma messages within 24 hours, but the most important German Enigma messages, those of the German U-boat submarines, could not be deciphered. The code breakers needed more information about the German Navy's Enigma, its operating procedures, and its settings. This information was gradually captured, literally, by boarding German ships and submarines at sea. The German Navy was fully aware of the possibility that its vessels might be boarded by the enemy, and made preparations to prevent their top secret Enigma machines and documents from being captured, both by making it easy to quickly remove the most critical Enigma parts and throw them to the sea before surrendering or abandoning the ship, and by making it easy for submarine crews to make their damaged U-boat sink shortly after it was abandoned by its crew. Although these security measures were usually successful, they were not full proof, and in a few occasions during the war, boarding teams from allied warships were able to capture Enigma operating manuals, settings lists, and even complete Enigma machines, which were not destroyed by the German crews before the boarding. A series of successful captures in mid 1941 allowed the British code breakers, for the first time, to read German naval Enigma messages almost in real time.
Some of these captures were part of carefully planned raids, in which British warships or commando units were sent for a raid whose only real purpose was to allow a single special intelligence officer to find and retrieve, sometimes under enemy fire, even just a few sheets of paper - the naval Enigma's monthly settings lists. Other captures involved a very heroic descent into a dark and knee-deep flooded German submarine, knowing that it is about to sink, in order to retrieve precious Enigma documents from it just before it sinks.
These amazing real war events are the material which create legends and inspire book and movie authors. Ian Fleming, which later became the author of the famous 007 James Bond series, was himself involved in planning Enigma capture operations. Some Enigma-related operations remained under a deep cover of secrecy for decades after World War 2. In my opinion, it is likely that even today there are still secrets from World War 2 which remain classified, either for national security reasons or for their political sensitivity.