×

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

Floating Point Operations and Associativity in C, C++ and Java

In this tutorial, we are going to compare Floating-point operations and the concept of associativity. Before we apply the concept of associativity in the floating-point operations in all three programming...

3 minutes read.

Print Table Using Do while Loop in C++

Multiplication Table In mathematics, a table is created by multiplying a certain number by all of the counting numbers, i.e., 1, 2, 3, 4, 5, 6, and so on. It is...

4 minutes read.

C++ | C Plus Plus While loop

In this article, we will discuss the C++ while loop with its syntax, use, key features, key points, pseudo code, and examples. What is the While Loop? The “while loop” is a...

4 minutes read.

Dynamic Constructor in C++

Dynamic constructors create dynamic memory by using a dynamic memory allocator new within the constructor. This allows us to initialize objects dynamically. The term dynamic constructor is used when memory...

2 minutes read.

C++ Goto

In this article, we will discuss the C++ goto statement with its syntax, use, key features, key points, pseudo code, and examples. What is the goto statement in C++? In C++, the...

4 minutes read.

Skyline Problem in C++

We have given n rectangular buildings in a 2-dimensional city. Here, to compute the Skyline of the given n rectangle structures in a two-dimensional metropolis while removing hidden lines, the...

3 minutes read.

Functions in C++ with Types and Examples

A function is a collection of statements that work together to complete a certain goal. It could consist of statements that execute repetitive operations or statements that conduct specialized jobs...

10 minutes read.

Learn C++ Tutorial

C++ Introduction C++ is an object-oriented programming language. It was developed by Bjarne Stroustrup at AT&T Bell Laboratories. It is superset (extension) of C programming language. Depending upon features supported by programming...

10 minutes read.

Diamond Pattern using While-loop in C++

What is while Loop? A while loop or while statement repeats all code of its body as long as a specific condition is satisfied. The loop ends if or when the...

5 minutes read.

C++ array to function

Arrays in C++ : Instead of defining distinct variables for each item, arrays are used to hold numerous values in a single variable. An array can be declared by specifying the variable...

4 minutes read.

Scope Resolution Operator in C++

The scope resolution operator and its different usage in the C++ programming language will be discussed in this section. The scope resolution operator is used to refer to an out-of-scope...

6 minutes read.

Nullptr in C++

What is Nullptr in C++? A null pointer value is represented by the term nullptr. Use a null pointer value to indicate that a native pointer type, inner pointer, or object...

3 minutes read.

Sliding Window Technique in C++

Sliding Window Technique or Window Sliding Technique is a computational technique that is mainly used to reduce the use of nested loop and replace it with a single loop. It...

4 minutes read.

Virtual Function Vs Pure Virtual Function

Virtual activity is a member function defined in the foundation phase that can be redefined by acquired classes. Let's have a look at an example: #include <iostream>   #include <bits/stdc++.h> #include <stdlib> using namespace std;   class Base   {    ...

5 minutes read.

How to concatenate two strings in C++

In the C++ programming language, the concatenation of two or even more strings is covered in this section. The term "string concatenation" refers to a collection of characters that join two...

4 minutes read.

C++ Math Functions

C++ Math Functions: Like other programming languages, C++ offers plenty of mathematical functions needed for various purposes. These functions are defined mainly in the math library in C++. Let us...

4 minutes read.

C++ find missing in the second array

Given two arrays A and B of sizes n and m. Find the elements from array A that are not present in array B. Example Input : a[] = {1, 2, 3, 5,...

3 minutes read.

Dynamic Memory Allocation in C++

In some programming situations, the number of data items changes as the program is running, which is known as dynamic data or input. Consider a real-world situation where a program...

3 minutes read.

Preventing Object Copy in C++

C++ is an object-oriented programming language that provides the ability to create objects, define class and pass objects to functions. When passing an object to a function or returning an...

7 minutes read.

Initialize Vector in C++

Initialize Vector in C++  The following comparison operators are defined for vector and those are given below. ==, <, <=, !=, >,>=  This allows you to access the element of a vector using...

3 minutes read.