×

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

C++ Socket Programming

In this world, computer networking has become very important for sharing of data. Every good programmer has some knowledge about computer networking. Socket programming is one of the critical topics...

6 minutes read.

Armstrong number using for loop in C++

What is For Loop? A for loop is a repetitive control structure that allows you to create a loop to execute a specific number of times efficiently. The syntax that can be...

4 minutes read.

Exception Handling in C++ vs Java

Nowadays, exception handling is a feature found in virtually all object-oriented languages. We can also find this type of feature in Java and C++. The try-catch and block is required...

3 minutes read.

External merge sort in C++

External merge sort in C++ External sorting is a concept for a group of sorting algorithms capable of handling large data volumes. External sorting is needed if the information getting sorted...

9 minutes read.

C++ Memory Management

Memory management is a method of controlling computer memory and allocating memory space to applications to increase overall system performance. What is the purpose of memory management? Because the array contains homogeneous...

4 minutes read.

Fast Input and Output in C++

In competitive programming, it's critical to read input as quickly as possible in order to save time. "Warning: Big I / O data, be aware of certain languages (but most...

3 minutes read.

Object Slicing in C++

In this article, we will learn about Object slicing. When an object from a derived class is assigned to an object from a base class in C++, these extra attributes...

3 minutes read.

C++ OOPs Concept

The main goal of C ++ programming is to add the idea of ​​object orientation to the C programming language. Inheritance, data binding, polymorphism and other concepts are part of...

4 minutes read.

Hello World Program in C++

The steps for “Hello World” C++ program are as follows: Write a C++ code given below in an editor. Save the file with .cpp Compile the code using C++ compiler or using online...

3 minutes read.

Include Guards in C++

In C++ programming, we frequently utilize a class more than once, so it is necessary to create a header file and include it in the main program. Now, occasionally a...

3 minutes read.

sort() function in C++

This tutorial covers the various built-in sort functions found in the C++ algorithm’s library.  What Does C++ Sort Mean? The concept of sorting in C++ entails rearranging an array's elements in a...

3 minutes read.

Scope Resolution Operator vs this Pointer in C++

In this tutorial, we will compare the Scope Resolution operation to this Pointer in C++ language. Scope Resolution Operator The Scope Resolution Operator in C++ programming language is usually denoted by (::)....

3 minutes read.

C++ Mutable keyword

C++ mutable keyword Mutable class storage specifier in C++ Storage class specifiers in C are auto, register, static, and external. Typedef is also considered as a specifier of the storage...

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.

Size_t Data Type in C++

In C++, the type to express the object size in bytes is defined as Size_t, an unsigned integer type offered by the standard library for describing the object's size and...

3 minutes read.

Reserved Keywords in C++

What are reserved keywords in C++? There are a few keywords that cannot be used as identifiers as those words are reserved for some other purposes, such keywords are called reserved...

15 minutes read.

Pattern programs in C++

In this article, we are going to discuss different pattern programs in C++. Program for Printing * patterns: Right Angle Triangle* pattern #include <iostream> using namespace std; int main() {     int rows;     cout <<...

3 minutes read.

Object in C++

In this article, we will learn about Object in C++. In short, an object is a stateful entity with behaviour. Data is referred to as state, and functionality is referred to...

3 minutes read.

Const Keyword in C++

The const programming language keyword will be covered in this section. The constant value that cannot change during program execution is defined using the const keywords. It implies that once...

9 minutes read.

C++ Call by Reference

Call by Reference is a C++ method for passing arguments to a function that enables us to pass the actual memory address of the parameter rather than a copy of...

4 minutes read.