DES Algorithm
•DES stands for Data Encryption Standard, which is a block algorithm that uses a key for encryption.
DES Algorithm Input Parameters
•The input parameters for the DES algorithm are three: Key, Data, Mode. The Key is 7 bytes or 56 bits long, serving as the working key for the DES algorithm; Data is 8 bytes or 64 bits long, which is the data to be encrypted or decrypted; Mode refers to the working mode of DES, which can be either encryption or decryption.
Algorithm Steps:
•The DES algorithm transforms a 64-bit plaintext input block into a 64-bit ciphertext output block, using a 56-bit key. The algorithm mainly consists of two steps:
1.Initial Permutation
The function is to rearrange the input 64-bit data block bit by bit and divide the output into L0 and R0, each 32 bits long. The permutation rule is to move the input’s 58th bit to the first position, the 50th bit to the second position, and so on, with the last bit being the original 7th bit.
L0 and R0 are the two parts after permutation output, where L0 is the left 32 bits of output, and R0 is the right 32 bits. For example, if the input value before permutation is D1D2D3…D64, then after the initial permutation the result is: L0=D58D50…D8; R0=D57D49…D7.
Permutation rules are as follows: 58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7,
1.Inverse Permutation
After 16 iterations, we get L16 and R16, which are used as input for the inverse permutation, which is exactly the reverse operation of the initial permutation, thus obtaining the ciphertext output.
This algorithm is a representative of symmetric encryption algorithms and is widely used in computer network systems.
IDEA Algorithm
Principle:
•IDEA is also a block encryption algorithm that encrypts data blocks of 64 bits in size with a key length of 128 bits, based on the design idea of “mixed operations on distinct algebraic groups.”
Key Generation:
1.The algorithm uses 52 subkeys (6 for each of the 8 rounds, and 4 additional for output transformation).2.The 128-bit key is divided into 8 subkeys of 16 bits each. These are the first batch of 8 subkeys (six for the first round, two for the second round). Then, the key is left-circularly shifted by 25 bits and divided into 8 subkeys again. The first 4 are used in the second round, and the last 4 are used in the third round. The key is again left-circularly shifted by 25 bits to produce another 8 subkeys, and this continues until the algorithm ends. Specifically, IDEA performs a total of 8 rounds of iterative operations, requiring 6 subkeys per round, plus 4 additional subkeys, resulting in a total of 52 subkeys, all derived from the 128-bit key.
Encryption Process:
1.The input 64-bit data block is divided into 4 sub-blocks of 16 bits: x1, x2, x3, and x4.2.These 4 sub-blocks serve as input for the first round, with a total of 8 rounds. In each round, the 4 sub-blocks are XORed, added, and multiplied with 6 subkeys of 16 bits.
The execution order in each round is as follows:
(1) Multiply X1 with the first subkey. (2) Add X2 to the second subkey. (3) Add X3 to the third subkey. (4) Multiply X4 with the fourth subkey. (5) XOR the results of steps (1) and (3). (6) XOR the results of steps (2) and (4). (7) Multiply the result of step (5) with the fifth subkey. (8) Add the results of steps (6) and (7). (9) Multiply the result of step (8) with the sixth subkey. (10) Add the results of steps (7) and (9). (11) XOR the results of steps (1) and (9). (12) XOR the results of steps (3) and (9). (13) XOR the results of steps (2) and (10). (14) XOR the results of steps (4) and (10). Each round's output is formed by the results of steps (11), (12), (13), and (14). The middle two sub-blocks are swapped (except for the last round) for the next round's input. After 8 rounds of operations, there is a final output transformation: (1) Multiply X1 with the first subkey. (2) Add X2 to the second subkey. (3) Add X3 to the third subkey. (4) Multiply X4 with the fourth subkey.
•The key length for the IDEA algorithm is 128 bits. The designers have made every effort to ensure that the algorithm is not susceptible to differential cryptanalysis.
MD5 Encryption Algorithm
•MD5 encryption is a one-way encryption algorithm.
MD5 Encryption Algorithm Principle
•The MD5 encryption algorithm processes the input information in 512-bit blocks, and each block is divided into 16 sub-blocks of 32 bits. After a series of processing, the algorithm’s output consists of four 32-bit blocks, which, when concatenated, produce a 128-bit hash value.•In the MD5 encryption algorithm, the information must first be padded so that the byte length modulo 512 equals 448. Therefore, the byte length of the information (Bits Length) will be extended to N512+448, or N64+56 bytes (Bytes), where N is a positive integer.•The padding method is as follows: A 1 is appended to the end of the information followed by a number of 0s until the above condition is met. Then, the length of the original information is appended as a 64-bit binary number. After these two steps, the byte length of the information is now N*512+448+64=(N+1)*512, making it a multiple of 512. This is done to satisfy the requirements for processing the information length in subsequent steps.•MD5 has four 32-bit integer parameters known as chaining variables (Chaining Variable), which are:
A=0x01234567 B=0x89abcdefC=0xfedcba98D=0x76543210
•Once these four chaining variables are set, the algorithm enters a four-round looping operation, with the number of loops equal to the number of 512-bit information blocks.•The four chaining variables are copied to four other variables: A to a, B to b, C to c, D to d. The main loop has four rounds (MD4 has only three rounds), and each round is quite similar. The first round performs 16 operations. Each operation performs a nonlinear function on three of a, b, c, and d, then adds the result to the fourth variable (one sub-block from the text and a constant).•Then the result is right-rotated by an arbitrary number of bits and added to one of a, b, c, or d. Finally, the result replaces one of a, b, c, or d. Below are the four nonlinear functions used in each operation (one per round).
F(X,Y,Z)=(X∧Y)∨(( X)∧Z) G(X,Y,Z)=(X∧Z)∨(Y∧( Z)) H(X,Y,Z)=X?Y?Z I(X,Y,Z)=Y?(X∨( Z)) where ? is XOR, ∧ is AND, ∨ is OR, and is NOT.
•If the corresponding bits of X, Y, and Z are independent and uniformly distributed, then each bit of the result should also be independent and uniformly distributed. F is a bitwise operation function. If X, then Y; otherwise Z. H is a bitwise parity operator. After all these steps, A, B, C, and D are respectively added to a, b, c, and d. The algorithm continues running with the next data block, and the final output is the concatenation of A, B, C, and D. The final result is A, B, C, and D, with A being the low-order byte and D being the high-order byte, forming a 128-bit output result.
Applications of MD5 Encryption Algorithm
•Due to its good security and the fact that it can be used freely in commercial applications, the MD5 encryption algorithm is widely used in digital signatures, file integrity verification, and password encryption.
Other Computer must-read books recommended for all of you include: "Computer Systems: A Programmer's Perspective", "C++ Primer", "Java Programming Ideas", "Fluent Python", "Data Structures (C++ Version)", "Algorithm Visualization", "Introduction to Algorithms", etc. How to get them: Long press the QR code to follow 【Java Programming Community】 👆 Long press the QR code above for 2 seconds Reply "196" to get the website Click "Read the original text" to view last week's exciting article.