What is des
Des has been widely used before, but with the progress of computer, now des can be brutally cracked. We no longer recommend using DES algorithm for historical reasons.
Encryption and decryption of Des
The key length of DES is 64 bits, or 8 bytes. But des every seven days
Bit will set an error check bit, so the real key length is 56 bits.
Because des has a length of 64 bits, it can only encrypt the original text with a length of 64 bits each time. If the original text is longer than 64 bits, it needs to be encrypted by multiple packets. The 64 bit unit is also called packet.
Block cipher is an encryption algorithm based on block cipher.
The schematic diagram of encryption and decryption is as follows:
Working principle of Des
DES is designed by Horst Feistel, so it is also called Feistel network.
Feistel network, each step of encryption is called round, the whole encryption process is a number of rounds of cycle.
The following figure shows a round of encryption process in Des
As can be seen from the above figure, in each round of operation, the input data is divided into left and right parts, and the middle sub key refers to the key used in this round of encryption. In Feistel network, each round uses a different key, which is only a local key, so it is called a subkey.
The operation steps are as follows
- Divide the input data into left and right parts
- Send the right side of the input directly to the right side of the output
- Send the right side of the input to the round function F
- The round function calculates a random number based on the data on the right and the subkey
- The random number obtained by 4 and the data on the left side are XOR operation, and the result after operation is taken as the left side of encryption.
We can see that in this round of operation, only the data on the left side is encrypted, and the data on the right side is not encrypted. Then we can exchange the data on the left and right sides and do another round of encryption. So the data on the right side is encrypted.
How to decrypt
Above we talked about the encryption process, next we look at the decryption process.
In the one-time password book, we talked about the characteristics of XOR, namely:
A XOR B = C
C XOR B = A
According to this feature, we only need to XOR the encrypted result with the random number calculated in step 4 to restore the data before encryption.
As shown in the figure below:
Special features of Feistel network
We can see that Feistel network has the following specific features:
- The number of rounds of Feistel network can be increased arbitrarily. No matter how many rounds can be decrypted normally.
- Decryption has nothing to do with round function f, and round function f does not need inverse function. Round functions can be designed to replicate enough.
- Encryption and decryption can be implemented using exactly the same structure. From what we have mentioned above, we can see that there is no difference between encryption and decryption.
Because des can be easily cracked by brute force, a triple des algorithm is developed.
Triple DES is a cryptographic algorithm that repeats DES algorithm three times. The encryption mechanism is as follows:
As shown in the figure above, the key length of Triple DES is 3 * 64bits.
And it is the process of encryption, decryption and encryption. A decryption process is added to the two encryptions.
This is to be compatible with the ordinary DES algorithm. If the three des keys are consistent, the Triple DES algorithm is equal to the ordinary DES algorithm.
For more tutorials, please refer to flydean’s blog