Des is a type of symmetric password. It uses a 56-bit key to encrypt a 64-bit long group.
Des performs 16 rounds of iteration on the content of each group. Each round of operation is the same but corresponds to different sub-Keys. All sub-keys are derived from the master key.
The 64-bit plaintext encryption process is as follows:
1. By-bit replacement (IP)
2. the plaintext is divided into l0 and R0.
3. L1 = R0 R1 = l0 1_f (r0, K1)
4. Repeat steps 3 and 16 times
5. By-bit replacement (IP ^-1)
The focus is:
1. How to Implement function f
2. How to generate a sub-key K
A simple answer is as follows:
1. The input and output data of function f are 32 bits.
E:
Divides the input data into eight 4-bit groups. This process is performed in the E box. E-box is a special replacement.
In 32-bit input, 16-bit input bits appear twice in the output. 1st 4 5 8 9 12... 32 bits
The input data in the e-box is 32 bits, and the output is 48 bits. Only the replacement operation is required.
S:
Perform XOR operations on the expanded 48-bit result and the key Ki, and send eight 6-bit long groups to eight different replacement boxes, crop the 6-bit output to 4-bit.
The input data in the S box is 48 bits, and the output is 32 bits. There are XOR operations with keys, and there is also replacement.
P:
Shifts by bit to achieve diffusion.
The input and output of the P box are both 32-bit, and only the replacement operation is required.
2. the input of the key generation function getkey is a 64-bit key, and the output is 16 48-seat keys.
The actual number of valid digits of the key is 56 bits, and the remaining 8 bits are odd parity bits. The 56-bit key obtained by PC-1 processing is divided into C and D. First, move C and D to one or two places based on the number of turns. Then C and D are combined, and 56-bit keys are replaced with 48-bit keys by a PC-2.
PC-1:
Replacement removes the check bit.
PC-2:
The meaning is to replace the 56 position with 48 digits.
Since I have not started writing code, first write the problems that I think may occur:
1. The most basic principle is how to implement replacement.
2. What is the key format: letters or numbers? How many digits?
3. During the function process, data should flow in binary format. How can binary be converted into letters and numbers? (Ah, this is not difficult)
Principles and implementation of DES