DES (Data Encryption Standard) is a symmetric key algorithm for data encrption. It is based on the two fundamental attributes of cryptography: substitution and transposition. DES consists of 16 steps, each of which is called a round. Each round performs the steps of substitution and transposition.
DES is a block cipher - it operates on plaintext blocks of a given size (64-bits) and returns ciphertext blocks of the same size.
-
Permutation of the original key
To generate subkeys a hexadecimel keyK
is needed. The 64-bit key is permuted according to thepc_1
table.NOTE: Only 56 bits of the original key appear in the permuted key.
-
Split the key into left and right halves
-
Series of left bit rotations
With left and right halves previously defined, sixteen operations of left bit rotations are performed. The number of bits to rotate is defined in theno_shifts
array. -
Permutation of the result
The key which is a concatenated pair of the halves obtained in the previous step is permutated according to thepc_2
table.
-
Initial permutation
Plaintext message is permutated according to theip
table. -
Split the message into left and right halves.
-
Applying
f
function
This step consists of 16 iterations. It usesf
function which operates on two blocks of data (data block and a subkey) to produce block of 32-bits.$L_n = R_{n-1}$
$R_n = L_{n-1} + f(R_{n-1}, K_n)$ where:
$L_n$ - left message half in the$n$ -th iteration
$R_n$ - right message half in the$n$ -th iteration
$K_n$ -$n$ -th subkeyTo calculate
f
first each block is expanded from 32 bits to 48 bits. This is done usingexpansion_table
. Next that output is XORed with subkey$K_n$ . The next step is to applys_boxes
array. To do that 48-bit message is split into eight groups of six bits.NOTE: First bit and last bit represent binary number from 0 to 3 which corresponds to the number of the row in the S-box. The middle 4 bits represent binary number from 0 to 15 which is the number of the column.
The final stage in the calculation of
f
is to do a permutation according to thep
table.That process is repeated for sixteen rounds. In the last round the order of two halves is reversed.
-
Final permutation
In this step the final permutation is applied according to the tableinv_ip
. Result of that operation is the encrypted message.
Decryption is simply the inverse of encryption. It follows the same steps as above, but the order in which keys are applied is reversed.
DES algorithm has been found vulnerable to powerful attacks and therefore, the popularity of DES has been found on the decline. It was officially withdrawn in 2005.