Triple DES Algorithm in C

In the field of cryptography, Triple DES (3-DES) is a symmetric-key block cypher that encrypts each data block three times using the Data Encryption Standard (DES) encryption algorithm.

After 1990, users of DES started to feel uneasy about the speed of exhaustive key searches against DES. Users did not wish to replace DES, however, because it is very expensive and time-consuming to update widely used encryption algorithms that are built into complex security structures. Instead of fully giving up on the DES, the realistic approach called for changing how it is used. As a result, Triple DES' modified schemes were created (sometimes known as 3DES).

The 3-key Triple DES (3TDES) and the 2-key Triple DES are two different versions of Triple DES (2TDES). Although triple DES systems are visibly slower than single DES, they are noticeably more secure than single DES.

Triple DES

The following is the encryption-decryption process:

  • The plaintext blocks with the single DES algorithm and key K1.
  • The result of step 1 will now be decrypted using single DES and key K2.
  • The output of step 2 should now be encrypted using single DES and key K3.
  • The cipher text is the result of step 3.
  • A cipher text can be decrypted in reverse. User encrypts with K2, and then uses K3 to decrypt before using K1 to encrypt.

Given that Triple DES is designed to be an encrypt-decrypt-encrypt operation, single DES may be implemented using a 3TDES (hardware) implementation by setting K1, K2, and K3 to the same value. This allows for DES backwards compatibility.

The only difference between the 2TDES and the 3TDES is that K1 is used in place of K3, not K3. In other words, the user encrypts plaintext blocks using key K1, decrypts them using key K2, and then re-encrypts them using key K1. Consequently, the key size for 2TDES is 112 bits.

Output:

The file generated contain below cipher:
1101111001100110111011110011011111111100011101111001100110111011110011011111111100010001001100110100010101
..................................................
Process executed in 2.22 seconds
Press any key to continue.

Explanation of Algorithm

Three DES keys, K1, K2, and K3, each measuring 56 bits, make up the "key bundle" used by triple DES (excluding parity bits). The algorithm for encryption is:

  • DES encrypt using K1, DES decrypt with K2, and then DES encrypt with K3 to create the ciphertext.
  • The reverse is true for decryption:
  • Plaintext is equal to DK1(EK2(DK3(ciphertext)) where EK2 stands for encryption and DK3 stands for decryption.





Latest Courses