Des symmetrically encrypted algorithms for detailed des profiles
Des is known as data encryption
Standard standard for data encryption, a block algorithm using key encryption, was established in 1977 by the national standards bureau of the united states federal government as the federal data processing standard (fips) and authorized for use in non-confidential government communications, which was subsequently widely disseminated internationally. It should be noted that, in some literature, des as algorithms is referred to as data encryption algorithms (data encryption algorinthm, dea) and is distinguished from des as standards。
The des algorithm is an algorithm that transforms 64-bit express input blocks into 64-bit secret output blocks and uses 64-bit keys
The des algorithm has three entry parameters: key, data, mode。
> key (key): 56-bit work key for 7 bytes and des algorithms (64-bit key, with 56-bit secret key plus 8 quizzes and 8, 16, 24, 32, 40, 48, 56, 64).
> data(data): 8 bytes 64 to encrypt or decrypted data
> mode(m): there are two ways of working for des: encryption or decryption。
Algorithmic characteristics: shorter grouping, shorter keys, shorter password life cycle, slower operation。
Unicode
Unicode has only one character set, and three words from china, japan and korea occupy parts of unicode that are 0x3,000 to 0x9fff
Unicode is currently using ucs-2, which encodes a character by two bytes, such as han bytes code 0x7ecf. Note that the character code is normally hexadecimal, which, in order to distinguish it from decimal, starts with 0x, converts 0x7ecf to decimal is 32463, ucs-2 is encoded by two bytes, which is 16 bytes binary, and 16 by two is equal to 65536 characters, so ucs-2 is capable of coding up to 65536 characters. The characters from 0 to 127 are identical to those from ascii, such as the "a" unicode is 0x0061, the "a" decimal is 97, the "a" ascii is 0x61, and the "a" is 0x61, and the "a" is 97. With the "a" code, the unicode is in fact not very good for hanwords, and it cannot be done, with a total of 670,000 characters in size and bulk, and the ucs-2 can mean a maximum of 65536 characters, more than 60,000, so unicode can only exclude some little-used hand words, which is good enough to be more than 7,000. In order to convey all hanwords, unicode also has ucs-4, which is coded by four bytes。
Des algorithm overall process equator
The flowchart of the des algorithm is easily available online, and we use the following for example and with our analysis:

Through the flowchart above, it is believed that you have an overview of the des encryption algorithm process。
We can translate into words:
Enter 64-bit explicit data at first;
an initial replacement (ip) is then performed;
after the initial replacement, the 64-bit data generated are divided into two parts, each 32-bit, named l0 (left0), r0 (right0);
then the two parts, with the participation of key k, perform 16 identical rounds of calculations based on function f, which we call the 16-wheeled inverted calculations, each time the name of the left and right two parts changes once, for example, after the first round of calculations, l0, r0, becomes l1, r1, until 16 studies are completed, l0, l16, r0, r16;
l16 and r16 are exchanged and merged to 64 bits after 16 rounds of operation have been completed; they are then replaced by the end (reverse replacement/termination replacement for the initial replacement) and the text is exported。
It should be noted that the 16 rounds of operation we have mentioned above are the same functions or algorithms used for the calculations, but the parameters l, r and k are not the same. L, r, and r are the l and r of the last calculations. But each round of k, which is involved in the calculations, is our entry parameter key, which, after a specific exchange of rules, generates 16 subkeys, which we name k1, k2, k3.... K16。
Approximate flow of function f
As mentioned above, 16 rounds of the same operation will be performed after the initial replacement, and we will now briefly describe what is done in this function, the main flow chart of which is as follows:

As we can see from the above figure, function f operates mainly on the right half of the data
1. To expand it into 48-bit data,
2. The resulting data are then differentiated from subkeys or calculated to obtain a new set of 48-bit data
3. Replace the s box with an odd or calculated 48-bit data, converting 48-bit data to 32-bit data. 4. Pbox replacement to generate 32-bit data
finally, the replacement of the pbox generated data with the l entered at the time of the current round of operation is used to produce new rs. 6. The new l is replaced directly by r in the current round
Des encryption achieves details ip replacement (initial replacement)
The rationale for the initial replacement is, in fact, simple. Based on an initial replacement table, it is sufficient to move the data at the corresponding location of the stated data to the location of the data against the values in the table, as follows:

From the above table, we can sum up the pattern of the initial replacement table:
1. An even number is separated from an odd number (d ~ 64) and then divided into two parts, top and bottom, distributed in a replacement table, an even number is above and an odd number is below. Within even and odd numbers, the order of “right to left, top to bottom, small to large” is followed。
As binary data are not easily visible after replacement, we present the initial replacement process without using the actual encrypted binary data instead of the letters, as follows:
We're going to replace it with: "abcdefghijklnopqrstuvwxyzabcdefhijlmnopqrstuvwxyz0123456789+"

As we understand it, a is the first of the 64-digit encrypted data, b is the second, by analogy, and the process of initial replacement should be as follows:
First step, replace a:

Then replace b:

Until the last one is replaced:

So we got the initial replacement data
Data = “5xphrjb7zrjbtld91tldvnf=3vnfxph4wogyqia6yqi(i)askc80skcume+2umewog”
From the whole process of the des encryption algorithm in the previous task, it is known that after the initial replacement is completed, the replacement data will need to be divided into l0, r0:
L0 = "5xphrjb7zrjbld91tldvnf=3vnfxph"
r0 = "4wogyqia6yqi(i) askc80skcume+2umewog"
Function f gives details
After the initial replacement, it's our 16-wheel operation, and what we need to know is the function of operation, and how data and keys are combined in the operation。
The f function acts on the k(subkey) value of each round and the right half(r) of each round of text to be encrypted. K-o, r-0 and so on. The numbers behind the letters are all k-r and so on。
From the flowchart of function f before us, it is clear that, after a round of calculations, the new l is the original r directly assigned value, i. E. L1 = r0, and the new r is the result of the departure or calculation of the original l from the original r processed by function f (r1 = l0^f(r0, k1)。
So what we need to understand now is these questions:
1. How did the subkey k ( " ~ 16) get it? 2. How the process of extending replacements was carried out, and what was the subsequent variation or calculation
3. How to replace the sbox
4. How does the pbox replacement work
Subkeyk
During the generation of subkey k, there are two additional replacements called compression replacement 1 and compression replacement 2, as follows:

From the flow chart, we can clearly tell:
1. The initial key generates 56 data after the first compression replacement,
2. Dissociate the 56 data from the center, named c0, d0, 28 data
3. C1 and d1 will then be obtained by moving the data left to the corresponding digits according to the number of rounds being calculated;
4. Finally, compression replacement 1 is not complete, combining c1, d1 with 56 bit data,
5. After a compression replacement of two, the subkey k1 is generated, i. E. The subkey used in the first round of calculations。
The subkey k in each of the next rounds was replaced by the two compressions of the previous generation. The difference is in the number of places left in the c and d cycles, which are different in each round. Specific correspondence tables are as follows (i. E. C1, d1 by c0, d0 by c2, d2 by c1, d1 and so forth):
So, after learning about the main process, let's take the example, and for a little intuitive, we'll replace the binary "0101" with "abc...":
Let's say our initial key is eight bytes, or 64 bits:
"abcdefgh ijklmnop qrstuvwx yzabcdef ghijklmn opqrstuv wxyz0123 456789+"
Compressive replacement 1
We split 64 data into eight groups, with the last data for each group being a quizz, which, although also a key, does not participate in encryption, i. E. Removes the red-redacted data, while the remaining 56 data need to be involved in compressing replacement 1 data, as shown below:

As with the initial replacements mentioned earlier, the letters can be changed to the corresponding position (in order to facilitate our indication of the position of the last participating letters in each row at the end of the initial key table, e. G., 7th and 15th), and after the replacement:

After this replacement, we can sum up the rule of compression for one:

It is to divide the 56-bit data into two groups according to the colours we have identified, and then in the order shown in the figure above。
After a compressed replacement of one, we get a k-0, split this k-0, get c-0, d-0, get c1, d1, get k1。
The compression replacement 1 is followed by split:
K0 = "4wogyqia 5xphrjb6yqi(i) askc7zrj+2umewog91tldvf80skcumebtld"
c0 = "4wogyqia5xphrjb6yqi(i)askc7zrj"
d0 = "+2umewog91tldvf80skcumebtld"
After the split, we get c0, d0, and then we're going to circle left
Based on the table corresponding to the `wheels and lefts', we are told that we are now asking for c1, d1, which is the first round of operations, so that the left of the cycle is one place, so we can get:
C1 = "wogyqia5xphrjb6yqi(i)askc7zrj4"
d1 = "2umewog91tldvf80skcumebtld+"
If you move left at the same time as the digits remain unchanged, the data that move at the top (left) is added later. C1d1 is then merged:
C1d1 = “wogyqia 5xphrjb6yqi(i) asskc7zrj42umewog91tldvf80skcumebtld+”
In the table (in the black table is the number of digits last in each row):

Compression replace2
To get the subkey k1, a compression replacement of 2 is required, and the 56-bit c1d1 is compressed to 48-bit k1:
The schedule followed for compression replacement 2 is as follows:

Get k1:

> k1 = "jyh7wqg4bispci(i)zyr56aarovbm1kdu0wc8ul+otsnm92e"
So we got the first round of real subkeys: k1
Extension e
We're going to find out about the extension e:
The effect of the extension replacement is to split the data into the right half r of the two parts (l, r) after our initial replacement。
The extension table is as follows:

It may not be easy to understand, and we describe in text that data r (32 bits) is divided into eight groups according to each four-digit group, as illustrated by the fact that the two black columns on both sides of the left and right are added to the extension, and that in the middle is data r after the grouping, the figures in the table represent the position in the data r. When divided into eight organizations, one such rule is followed:
1. The end of each group is added to the end of the group,
2. At the end of each group, add the head of the lower group of data in this group。
That's the first set of data, with the last in the last set added, the first in the second set... And so on
If i don't get it, i'll put one more figure:

All right, now expand the r0 we got above:
Group first:
R0 = "4wogyqia6yqi(i) askc80skcume+2umewog"

Then they expand:

Then we got the r0 to 48:
R0 = "g4wogyyqia6a6yqi(i)ai(i)askc8c80skkkccume+e+2umewog4"
After the extension of e, what we're going to do is a different or different calculation of k1 and r0, and since we're not using real binary data here, we're not going to do a detailed explanation of this step, which is, after all, a different or an operation, which is simple。
Sbox instead
The effect of the s box instead is to compress the 48-bit data from r0 to k1 or later to 32-bit data。
There are eight s boxes, each of which is an array of 16 columns in four rows, as follows:




Now let's talk about the process of replacing the sbox:
1. With the 48-bit r0 data that we obtained after the extension, and eight of our s boxes, we would need to divide the r0 into an average of eight groups, each corresponding to one s box. The length of data in each group is 6-bit, assuming that the binary data in the first group are: "100110"
so, we take the first and the last and make up the decimal lines: "10" = 2
then take the middle four and form the decimal column: "0011" = 3
5. Then, in the corresponding s1 box, take the data in 2 rows of 3 column (column 4 of line 3):8
conversion of the obtained number to binary: "10000"
7. To replace this four-digit binary data with the six-digit data from the original cluster i, so that when the eight s boxes are replaced, we get 32-bit data。
Pbox switch
After the replacement of the s box has been completed, the p box has been replaced and the 32-bit data entered and the output is 32-bit. Examples of replacement tables and replacements are as follows:

So we got the f (r0, k1), we got the final r1, we got the first round, we got l1, we got l1。
End replacement (also referred to as reversal/termination replacement for initial replacement)
After 16 calculations, we get "l16, r16" at the end of function f, which is exactly what we need, and then we merge l16 and r16, but unlike the merger in the previous steps, this merger requires the exchange of both positions, that is, r16l16。
After the merger, we got 64 bits of data, and with 64 bits of data, we've got encrypted data。
The termination of the replacement form is as follows (we will not give any more examples, anyway):

We are simply doing the following simple encryption steps with python, which we did not consider in this experiment:
1. What about texts requiring encryption that exceed 64 or less? 2. How the encrypted text is displayed (this involves coding problems) and our code is run after the final encrypted binary data is displayed directly
3. What if the user enters a key of 64 or less? 4. How to declassify (which also involves the issue of coding), i. E. Our code is only encrypted and not decrypted
That's to use python to show the encryption details.
We must first prepare replacement forms for encryption:
Initial and termination replacement tables:

Eight s boxes:


P box

Compressive replacement table

Extension table

We know that both the text to encrypt and the key are processed in binary form during the encryption process, so we need a function to process all incoming strings and convert them to binary, and we use the word function to convert the entered data to their corresponding unicode decimal, and then to binary, because the bin function of python automatically deletes the high zero, so we use "{:08b}. Format()" in this way, the generated binary is kept to a certain number of digits:

We start with the generation of sub-keys, as illustrated below, by creating a sub-key-generated binary version of the initial key with the required parameters, which, based on the knowledge of the principle before it, is replaced by compression, divided into c and d parts, then moved, 16 moves completed in one breath, and the resulting sub-keys are all stored in the global list ks, and the convenient encryption function calls on these sub-keys:

The encryption function, instead of going into it here, is understandable to read the notes in the code。



Execute script to encrypt the string "testtest" with the key "12345678":

Other organiser

References
;seid = 180201048










