Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Cryptography Technique
2.1.
Symmetric Key Cryptography
2.2.
Asymmetric Key Cryptography
3.
Diffie-Hellman Problem
3.1.
Problem description
4.
Diffie Hellman Key Exchange
4.1.
Diffie Hellman Key Exchange Algorithm
4.2.
Step 1
4.3.
Step 2
4.4.
Step 3
4.5.
Example
5.
Frequently Asked Questions
5.1.
What algorithm does Diffie Hellman use?
5.2.
How does the Diffie-Hellman algorithm work?
5.3.
What is cryptography?
6.
Conclusion
Last Updated: Mar 27, 2024

Again Hellman, Diffie-Hellman Problems

Author Aditi
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Have you wondered how cryptography is done? Or How is data transferred without letting the attackers know about the data?

This article is focused on one of the famous problems of cryptography, the Diffie-Hellman Problem. Cryptography is a way of storing data and transmitting it in a particular form. Diffie hellman is a cryptography problem or algorithm that helps to transfer data with the help of two different keys. 

Let’s dive into the article to learn more about the Diffie-Hellman Problem.

diffie-hellman-problem

Cryptography Technique

Before we move forward with the Diffie-Hellman Problem, you need to know more about cryptography techniques. Cryptography techniques are of two types. They are as follows:-

Symmetric Key Cryptography

This type of cryptography uses a single secret key to encrypt and decrypt messages. There is a major issue with secret key exchange with this cryptography technique. It isn't easy to share between the sender and the receiver. Attackers can intrude; while exchanging, they can know the secret key.

Asymmetric Key Cryptography

This type of cryptography uses different keys to encrypt and decrypt messages. Both sender and receiver use distinct keys. It is also known as public key cryptography. There are two famous asymmetric encryption algorithms, RSA and Diffie-Hellman Key Exchange. 

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Diffie-Hellman Problem

Whitfield Diffie and Martin Hellman proposed a mathematical problem called Diffie-Hellman Problem (DHP) in cryptography. At that time, many security systems used only one-way functions. Those were computed fast, and it was very hard to reverse. For example, encryption of messages is enabled, but reversing (decryption) is difficult. This problem was solved by DHP. Let's move toward the description of the problem.

Problem description

The problem can be stated as follows:

and y are random integers, and is a generator of some group, often an elliptic curve group or the finite field multiplicative group. An eavesdropper can observe g^x and g^y being transferred as part of the Diffie-Hellman key exchange protocol. Then both parties can compute the g^(xy) as a shared key.

Is the above statement hard to understand? Don't worry. In simple words,  given an element, g. g^x and g^y values are also given. Then what will be the value of g^(xy)

Diffie Hellman Key Exchange

The diffie-Hellman key exchange algorithm is an Asymmetric Key Cryptography algorithm. This algorithm uses different keys for encryption and decryption. There is an exchange between the sender and the receiver of the secret key. This algorithm makes it easier to trade secret keys without actually sending them.

Diffie Hellman Key Exchange Algorithm

Let,

P1 = Member 1 Private key

R1 = Member 1 Public key

P2 = Member 2 Private key

R2 = Member 2 Public key

The key will be exchanged using Diffie Hellman Algorithm in the following steps:-

Step 1

There are two members between whom messages will interchange. So one member will choose two numbers. Let's say ‘x’ and ‘y’ such that the ‘y’ prime number primitive root is ‘x’. These numbers will be exchanged with the other member. After exchanging, both members now know the value of ‘x’ and ‘y’.

Step 2

Members know their private keys. Both members have separate private keys. Now at this point, both members will calculate their public key value. After calculating the public key, they will exchange the public keys with each other.

Step 3

This is the last step. At this moment, both members have the other member's public key. Both members now calculate the secret key value. Finally, both members will obtain the same secret key value.

Example

It’s time to understand the algorithm with an example. 

Step 1: There are two variables, 'x' and 'y'. 

y = 23 ( prime number as modulus )

x = 7 ( prime number primitive root )

Now, both members also have their private keys. Their value is as follows:-

P1 = 3 ( private key of member 1)

P2 = 6 ( private key of member 2)

Step 2: Both members will calculate their public key value. Then values will exchange with each other.

Public key of member 1 (R1) = (x^P1) mod y

      = (7^3) mod 23

      = 21

 

Public key of member 2 (R2) = (x^P2) mod y

      = (7^6) mod 23

      = 4

 

Step 3: Now, both members will calculate the secret key value on their side.

Secret key obtained by member 1 = (R2 ^ P1) mod y

      = (4^3) mod 23

      = 18

 

Secret key obtained by member 2 = (R1 ^ P2) mod y

      = (21^6) mod 23

      = 18

Finally, both members have the same secret key value, i.e., 18.

Frequently Asked Questions

What algorithm does Diffie Hellman use?

Diffie Hellman uses a private-public key pair. It establishes a shared secret, like a symmetric key. But it is not a symmetric algorithm. It is an asymmetric algorithm. DH is used to establish a secret key for a symmetric key algorithm.

How does the Diffie-Hellman algorithm work?

The Diffie–Hellman Algorithm is a key-exchange protocol. It enables two parties to communicate over public channels to establish a mutual secret. This secret is not being transmitted over the Internet. It allows the use of a public key for encryption and decryption of their conversation or data using symmetric cryptography.

What is cryptography?

Cryptography techniques include confidentiality, non-repudiation, integrity, and authentication. There are three types of cryptography. They are symmetric, asymmetric, and hash values. Examples of cryptography are DES, AES, RSA, and Diffie-Hellman key exchange.

Conclusion

This complete article has helped us to learn about all the concepts of the Diffie-Hellman Problem of Cryptography. We have also explained cryptography techniques and then the diffie-hellman key exchange algorithm.

We hope this blog has helped you enhance your Cryptography knowledge. Practice makes a man perfect. To practice and improve yourself in the interview, you can check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews.

Do upvote our blog to help other ninjas grow. Happy Coding!

thank you
Previous article
Semantic Security of ElGamal System
Next article
What is a Signature Scheme?
Live masterclass