In 1976, **Whitefield Diffie and Martin Hellman** arrived up with Diffie Hellman key exchange Algorithms to solve the problem of agreeing on and exchanging keys, which can be utilized for encryption and decryption. It lets two people who want to talk to each other agree on a symmetric key. If you are in search of **Which Algorithm helps in Key Exchange**, then you are at right place.

* Remember that the Diffie-Hellman key exchange algorithm can only be used for key exchange and not for encryption and decryption*. Mathematical principles are used to make up the algorithm.

Table of Contents

**Which Algorithm helps in Key Exchange – The Behind Process**

The algorithm is established on Elliptic Curve Cryptography, a way to do public-key cryptography found in the algebraic form of elliptic bend over finite fields. The DH, like many other ways to do public-key cryptography, also uses the trapdoor function. The DH Algorithm is easy to understand if you remember the following.

- The first person chooses two prime numbers, g, and p, and tells the second person what they are.
- The second party then determines a secret number (let’s call it a), calculates ga mod p, and sends back the result, which we’ll call A, to the first party. Remember that no one gets the secret number, only the result.
- The first party then does the same thing; it chooses a secret number b and figures out the result B, just like in step 2.
- The result is then sent to the second person.
- The second party takes the number B sent and figures out B mod p.
- The first party takes the number A sent and figures out Ab mod p.

Now things get interesting because the answer to step 5 is the same as step 4. This means that both sides will get the same answer no matter what order of exponentiation is used.

(ga mod p)

b mod p = gab mod p\s(gb mod p)a mod p = gba mod p

The shared secret key will be the number we got between steps 4 and 5. This key can be used to encrypt and send any data, like blowfish, AES, etc.

**The Diffie–Hellman Algorithm**

- key =(YA)XBmod q -> B came up with the same answer.
- Global Public Elements

q: q is a prime number a: an is more minor than q and is the primitive root of q - Making a key for user A

Choosing a Private key XA Here, XA <q

Here’s how to figure out the public key YA: YA = aXA mod q. - Making a key for user B

Choose an XB Private key. Here, XB q

Now, we’ll figure out the public key. YB YB = and mod q - To figure out the secret key, use the A key and (YB)XA mod q.
- Use the B key to figure out the secret key: (YA)XB mod q

**Example**

- Both Alice and Bob use a public phone number P = 23, G = 5
- Alice chose private key a = 4, and Bob chose private essential b = 3.
- Both Alice and Bob can now figure out what x and y are worth by doing the following:

Alice: x = (54 mod 23) = 4

Bob: y = (53 mod 23) = 10 - Now, like Alice and Bob, give each other their public phone numbers.
- Now, Alice and Bob figure out the symmetric keys.

Alice: ka = ya mod p = 104 mod 23 = 18

Bob: kb = xb divided by p = 43 divided by 23 = 18.6. This is the secret shared key.

**Uses of the Diffie Hellman Algorithm**

DH Algorithm can be used for more than just making public keys. Here are some other ways it can be used:

**Encryption**

The Diffie-Hellman key exchange algorithm can be used to encrypt. ElGamal encryption was one of the first ways to do this. One modern example is the Integrated Encryption Scheme, which protects against chosen plain text and clipboard attacks.

**Password-Verified Agreement**

A password-authenticated key agreement can stop the “Man in the Middle” attack when two people share a password. Diffie-Hellman is one way to make this key agreement. This method is used in Secure Remote Password Protocol, a good example.

**Forward Secrets**

Forward secrecy-based protocols can make new key pairs for every new session and automatically throw away the old ones when the session is over. Most of the time, the Diffie-Hellman key exchange is used in these forward-secrecy protocols.

**Some Related Articles: **

**Pros of the Diffie-Hellman Algorithm**

- The sender and receiver don’t have to know each other ahead of time.
- Once the keys are swapped, data can be sent through a channel that is not secure.
- It’s safe to share the secret key.

**Cons of the Diffie-Hellman Algorithm**

- The algorithm can’t be used to exchange keys in a way that doesn’t make sense.
- In the same way, you can’t use it to sign digital signatures.
- A man-in-the-middle attack is possible with the Diffie-Hellman key exchange because it doesn’t verify any of the parties involved in the transmission.

**Conclusion**

The Diffie-Hellman key exchange has been proven to work because of its benefits. Even though it is hard for someone to decrypt the data and get the keys by snooping on the network, it is still possible if the generated numbers are not entirely random. Also, a man-in-the-middle attack is possible with the key exchange system. To avoid it, both parties should be careful at the start of the exchange. Hope you get a proper idea about **Which Algorithm helps in Key Exchange.**