---
title: "Short note: Diffie-Hellman"
subject: "Computer Networks and Security"
chapter: 8
key: "semester_7/computer_networks_and_security:diffie-hellman-note"
source: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/diffie-hellman-note
site: BCT Engineering
---

# Short note: Diffie-Hellman

Computer Networks and Security · Chapter 8: Network Security

- Asked in: 2074 Asoj, 4 marks
- Video: [Diffi Hellman Key Exchange Algorithm | Cryptography and Network Security](https://www.youtube.com/watch?v=zLNug0LrFiU) — Abhishek Sharma
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/computer_networks_and_security/diffie-hellman-note
- Whole chapter: https://www.bctengineer.com/md/semester_7/computer_networks_and_security/chapter-8

## Question

Write a short note on Diffie Hellman's algorithm.

## Short answer

Diffie-Hellman enables two parties to establish a shared secret over an insecure channel without prior meeting. They agree on a large prime p and generator g, exchange public values g^a mod p and g^b mod p, then compute the shared key g^ab mod p. Security depends on the discrete logarithm problem. It lacks authentication and is vulnerable to man-in-the-middle attacks unless combined with digital signatures or certificates.

## Answer

The **Diffie-Hellman (DH) algorithm** (1976) lets two parties agree on a **shared secret key over an insecure channel** without having met before. It is a key-exchange method, not an encryption method. Its security depends on the difficulty of the **discrete logarithm problem**.

#### Steps
1. Alice and Bob publicly agree on a large prime **p** and a generator (primitive root) **g**.
2. Alice chooses a secret a and sends A = gᵃ mod p. Bob chooses a secret b and sends B = gᵇ mod p.
3. Alice computes K = Bᵃ mod p; Bob computes K = Aᵇ mod p.
4. Both get the same K = gᵃᵇ mod p, used as the symmetric session key.

#### Example
p = 23, g = 5, Alice's secret a = 6, Bob's secret b = 15.

| Step | Alice | Bob |
|---|---|---|
| Public value | A = 5⁶ mod 23 = 8 | B = 5¹⁵ mod 23 = 19 |
| Exchange | sends 8 | sends 19 |
| Shared key | 19⁶ mod 23 = 2 | 8¹⁵ mod 23 = 2 |

**Shared key K = 2.** An eavesdropper sees p, g, 8 and 19, but cannot easily find a or b for large p.

#### Weakness
It does not authenticate the parties, so it is open to a **man-in-the-middle attack**; digital signatures or certificates are used to prevent it. It is used in IPsec (IKE) and SSL/TLS.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is DH?
   A. Key-exchange method for a shared secret over an insecure channel
   B. Signature only
   C. Encryption method
   D. Hash
   Answer: A. It is not an encryption method. (Key point: Purpose)

2. Security depends on:
   A. Hash collisions
   B. Discrete logarithm problem
   C. Factoring
   D. Short keys
   Answer: B. Finding a or b from g^a mod p is hard. (Key point: Security basis)

3. p=23, g=5, a=6: A =
   A. 8
   B. 2
   C. 6
   D. 19
   Answer: A. 5^6 mod 23 = 8; shared key 2. (Key point: Example)

4. What attack is DH open to?
   A. Brute force on a
   B. Replay only
   C. Man-in-the-middle, since parties are not authenticated
   D. None
   Answer: C. Signatures or certificates prevent it. (Key point: Weakness)
