Enigma Algorithm

        In this community I found a lot of articles about the famous Enigma cryptographic machine, but the detailed algorithm of its operation was not described anywhere. Surely many will say that this does not need to be advertised - but I hope that it will be useful to someone to find out about it. How did it all start? During the First World War, the Playfair cipher was very popular. Its essence was that the letters of the Latin alphabet were written in a 5x5 square, after which the letters of the original alphabet were divided into pairs. Further, using the square as a key, these bigrams were replaced with others according to a certain algorithm. The advantage of this cipher was that it did not require additional devices, and, as a rule, by the time the message was decrypted, it was already losing relevance.

image


        This device consisted of a certain number of disks strung on a single axis (usually there were 36 disks). Each of them was divided into 26 parts, each of which denoted a letter. The letters on the discs were arranged in random order. The operator, by rotating the disks, dialed the desired message, and then rewrote another line. The person who received this message should have had exactly the same device with exactly the same arrangement of letters. Both methods were relatively good for those times, but given that humanity has entered the 20th century, the need arose to mechanize the encryption process. In 1920, the Dutch inventor Alexander Koch invented the first rotary cryptographic machine. Then, German inventors obtained a patent for it, who improved it and put it into production, under the name "Enigma" (from Greek. - a riddle). Thus, this machine was acquired by many companies that wanted to keep their correspondence secret. This was the whole genius of Enigma - everyone knew the encryption algorithm, but no one could pick the right key, since the number of possible combinations exceeded 15 quadrillion. If you want to know how Enigma was hacked, I advise you to read Simon Singh's book “The Book of Ciphers”. Summing up all of the above, I want to say that the Enigma cipher was a mixture of the Jefferson cipher and Caesar's cipher. since the number of possible combinations exceeded 15 quadrillion. If you want to know how Enigma was hacked, I advise you to read Simon Singh's book “The Book of Ciphers”. Summing up all of the above, I want to say that the Enigma cipher was a mixture of the Jefferson cipher and Caesar's cipher. since the number of possible combinations exceeded 15 quadrillion. If you want to know how Enigma was hacked, I advise you to read Simon Singh's book “The Book of Ciphers”. Summing up all the above, I want to say that the Enigma cipher was a mixture of the Jefferson cipher and Caesar's cipher.

        So, we begin to study the algorithm. On this siteThere is a very good simulator, which in an accessible and visual form shows the whole process in its entirety. Let's look at the principle of operation of the three-rotor Enigma. It had three compartments for accommodating three rotors and an additional compartment for accommodating the reflector. In total, during the Second World War, eight rotors and four reflectors were made, but at the same time, exactly as much as the machine was designed could be used. Each rotor had 26 sections, which corresponded to a separate letter of the alphabet, as well as 26 contacts for interaction with neighboring rotors. As soon as the operator clicked on the desired letter, the electric circuit was closed, as a result of which an encrypted letter appeared. The circuit was closed due to the reflector.

image


       The illustration shows the illustration of pressing the “A” key followed by decryption into the letter “G”. After entering the letter, the rightmost rotor moved forward, thereby changing the key. So how was one letter replaced by another? As I said, eight different rotors were developed for Enigma. Inside each of them, 26 different commutations were installed. HereA detailed specification for each of them is presented. For example, if the letter “N” entered the input of the first rotor, then the output should be only “W” and no other letter should be larger. If it were a letter on the second rotor, it would have already converted to "T", etc. That is, each rotor performed a clearly defined task in terms of communication. But what role did the rings play? Consider the following example. Set the rotors III, II and I, and the order of the rings is “C”, “U” and “Q”.

image


        Press the "A" key. The rightmost rotor will turn one step forward, that is, the letter “Q” will go to “R”. The rotor in the middle will also turn forward to the letter “V”, but I will talk about this a bit later. So, our letter “A” begins the journey from the first compartment in which rotor I is installed and on which the letter “R” is already set. Before entering the first rotor, the letter undergoes its first transformation, namely: addition with the letter "R" modulo 26. In fact, this is Caesar's code. If you number all the letters from 0 to 25, then the letter "A" will be exactly the same zero. So, the result of the addition will be the letter "R". Further, you and I know that in the first compartment the rotor is I, and in its design it is laid down that the letter “R” always goes into “U”. Now in turn is the second compartment with rotor II. Again, before hitting the second rotor,differencevalues ​​of the subsequent rotor and the previous one. I will explain. On the second rotor, the letter “V” awaits us, and on the previous rotor, “R”, their difference is four letters, and it is they that are added to our letter “U”. Therefore, the letter “Y” enters the second rotor. Further, according to the table, we find that in the second rotor the letter “Y” corresponds to “O”. Then again we look at the difference between the letters "C" and "V" - it is equal to seven. So, we shift the letter “O” by seven positions and get “V”. In rotor III, “V” goes into “M”. Before you get to the reflector, the letter “C” is subtracted from our letter, transforming it into the letter “K”. Next comes the reflection. If you notice, in each rotor large cyclic groups are formed, for example: (A - E - L - T - P - H - Q - X - R - U), and in the reflector they are divided into pairs: (A - Y) (B - R) (C - U), etc. This is done so that later it can be decrypted. Suppose a reflector B is installed in which “K” is replaced by “N” (and vice versa). Half way passed. Now we again add the value of the letter “C”, thereby obtaining the letter “P”. Here, on the contrary, in the line of the third rotor we find “P” and look at which letter it would appear when you click. This is the letter "H". The conversion in the third rotor is completed. Now the difference between the letters “C” and “V”, that is, seven, is subtracted from this letter. We get the letter "A". In the second rotor, it passes into itself, so we leave it unchanged. Next, subtract the difference between the letters “V” and “R”, that is, the four and get the letter “W”. In the first rotor, its inverse transformation is displayed in the letter "N". It remains only to subtract the letter "R" from it and get the desired letter "W". As you can see, the algorithm of the machine was not as complicated as it seemed. To improve the cipher, the Germans introduced a patch panel that allowed them to swap letters in pairs. If we combine the letters “Q” and “W”, then by entering the same “A” we would get “Q”, since in fact there should be “W”, but it is replaced by the letter “Q”. Here is the attached action diagram.
image
        It remains only to talk about the displacement of the rotors relative to each other. The right rotor always turned when one key was pressed. For example, for rotor I, this position is equal to the letter “R”. That is why in our example, the second rotor turned: the first rotor passed through the letter "R". Further, having passed through a certain position, the right rotor set in motion the left one step. In more advanced models, the left rotor scrolled two, or even three times.

        In conclusion, I will say that here are some materials on hacking Enigma that can be useful. I hope this article is useful to someone.

Also popular now: