×

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.

Related Topics

Divide by Zero Exception in C++

We use exception handling method to handle the divide by zero exception. Dividing a number with zero is generally mathematical error. We have to exception handling method to overcome this...

2 minutes read.

Constructor Overloading

The program contains more than one constructor in a class with the same name, and different types of arguments are called constructor overloading. Calling of constructor depends on the number and types...

2 minutes read.

Program to find the GCD of two numbers in C++

Before understanding the program of GCD or HCF, one must know what GCD or HCF is. What is GCD? The GCD is referred to as Greatest Common Divisor. HCF is the other...

8 minutes read.

Is it fine to write void main() or main() in C/C++?

In C programming language: The default function return type in the C programming language is "int," which implies that main() will always return an integer value. In C, the void main()...

3 minutes read.

Containership in C++

In C++, it is possible to create an object in one class into another class, and that object is a member of another class. This relationship is known as a...

4 minutes read.

C++ | C Plus Plus Data type

Data type in every language is very important. Data type means the different kinds of data that are supported by a particular programming language. A computer language’s data types specify the...

15 minutes read.

How to Use Getline in C++

What is getline in C++? Similar to the cin function, which allows the programmer to take input from the user getline() function also takes input from the user. But in this...

4 minutes read.

Hospital Management Project in C++

The following capabilities are required to build a hospital management project: These are as follows: hospitals' names, contact information, and lists of doctors and patients. Activities Supported Hospital Data Print Patients' data to...

4 minutes read.

C++ Variable

In this article, we will discuss variables in C++ with their types and examples. What are Variables? Variables are specific memory storage spaces that hold a value. During the execution of a...

4 minutes read.

Bit Manipulation in C++

The high-level language in which we communicate is not understood by the computer. As a result, there existed a standard mechanism for understanding any instruction sent to the computer. At...

5 minutes read.

Web Development in C++

Before learning above C++ web development, we need to learn about CGI What is CGI? CGI stands for common gateway interface. CGI is a standard that tells us how the exchange of...

4 minutes read.

C++ Namespaces

An Overview In each scope, a name can only represent one entity. As a result, there cannot be two independent variables with the similar names in the same scope, as this may cause...

10 minutes read.

C++ operator

In this article, we will discuss about the operators in C++ with their types and examples. An operator is specially a symbol that tells compiler to perform specific manipulation. C++ contains...

5 minutes read.

Returning Multiple Values from a Function using Tuple and Pair in C++

We may come across many situations where after the driver code's execution is performed in a code block, the return should be either multiple values or a single value possibly...

4 minutes read.

Processing strings using std string stream in C++

A string class object called std: string stream is used to streamline into various variables, just as files can pour into strings. This class's things make use of a string...

3 minutes read.

Hexadecimal to Decimal in C++

In computers, hexadecimal numbers are represented with base 16 and decimal numbers are represented with base 10 and values 0-9, whereas hexadecimal numbers have digits ranging from 0 to 15,...

3 minutes read.

gmtime() function in C/C++

C++ language is used to make high-performance applications that can work efficiently. It is one of the world's most popular languages. It is an object-oriented and high-level programming language, which...

4 minutes read.

Program to arrange an array in alternate positive and negative numbers

Let’s say, there is given an array arr, arrange the array in such a way that every positive number is followed by a negative number. If there are extra positive...

4 minutes read.

C++ Virtual Destructor

In C++, a destructor is a class member function that is used to free up space or remove an object of the class that has gone out of scope. The...

4 minutes read.

C++ String Class and its Applications

The String class is available in C++. The character array is represented by the C string. The string class in C++ has a few different attributes. It contains several functions...

4 minutes read.