DES in C++
- The popularity of the Data Encryption Standard (DES) is slightly declining as a result of the discovery that DES is susceptible to very strong attacks.
- Since DES is a block cypher, it encrypts data in blocks of 64 bits each. As a result, DES receives 64 bits of plain text as input and outputs 64 bits of ciphertext.
- With a few minor variations, the algorithm is the same and for encryption and decryption, the keys used are the same.
- The key is 56 bits long.
- We have said that the key used by DES is 56 bits.
- The original key has 64 bits in it.
- However, before the DES process ever starts, every 8th bit of the key is deleted to yield a 56-bit key.
- That is bit locations 8, 16, 24, 32, 40, 48, 56, and 64 are eliminated.
- As a result, the original 64-bit key is reduced to a 56-bit key by throwing away every eighth bit of the key.
- DES is based on substitution (also known as confusion) and transposition, two key components of cryptography (also called diffusion).
- Each of the 16 stages in DES is referred to as a round.
- The stages of substitution and transposition are carried out in each round.
- Now let's talk about the fundamental DES stages.
- The 64-bit plain text block is sent to the initial Permutation (IP) function in the first phase.
- On plain text, the initial permutation is carried out.
- Next, the initial permutation (IP) creates Left Plain Text (LPT) and Right Plain Text (RPT), which are the two sides of the permuted block (RPT).
- The encryption process now goes through 16 cycles for each LPT and RPT.
- Finally, LPT and RPT are reunited, and the combined block is subjected to a Final Permutation (FP).
- This process generates 64-bit ciphertext as the result.
Permutation initial (IP):
- As previously mentioned, the initial permutation (IP), which occur before to the first round, only occurs once.
- The graphic illustrates how it thinks the transposition in IP should go.
- As an illustration, it states that the IP swaps out the first bit of the original plain text block for the 58th bit, the second bit for the 50th bit, and so on.
Key transformation in Step 1:
- We have noticed original 64-bit key is turned into a 56-bit key by removing every 8th bit of the initial key.
- Consequently, a 56-bit key is accessible for each.
- A procedure known as key transformation is used to create a unique 48-bit Sub Key from this 56-bit key throughout each round.
- The 56-bit key is split into two parts, each of 28 bits, for this purpose.
- Depending on the round, these halves have a circular left shift of one or two locations.
- As an illustration, the circular shift is performed by two places for additional rounds if the round number is 1, 2, 9, or 16.
- 48 of the 56 bits are chosen after the proper shift.
- The table is depicted in the image below for choosing 48 of the 56 bits.
- For instance, bit number 14 shifts to the first place following the shift, followed by bit number 17, and so on.
- We can see that the table only has 48-bit locations if we look at it closely.
- To reduce a 56-bit key to a 48-bit key, bit number 18 is discarded along with 7 other bits (bit number 18 will not appear in the table).
- Compression Permutation is the name given to the key transformation procedure because it chooses a 48-bit subset of the original 56-bit key and involves permutation.
Step-2: Expansion Permutation:
- Remember how we had two 32-bit plain text areas called Left Plain Text (LPT) and Right Plain Text after the initial permutation? (RPT).
- The RPT is increased during the expansion permutation from 32 bits to 48 bits.
- The term "expansion permutation" refers to the permutation of bits as well.
- This occurs because the 32-bit RPT is split into 8 blocks, each of which has 4 bits.
- Subsequently, each 4-bit block of the preceding phase is then enlarged to a matching 6-bit block, i.e., each 4-bit block, 2 extra bits are added.
- While producing output, this process causes the input bit to expand and be permuted.
- The 56-bit key is compressed to 48 bits during the key translation procedure.
- Then the expansion permutation procedure grows the 32-bit RPT to 48-bits.
- The 48-bit key is now XORed with the 48-bit RPT, and the output is then passed on to the S-Box substitution, which is the following step.