✦ ✦ ✦

The Discrete Logarithm
Problem
& Diffie-Hellman

How does your browser keep secrets over a public channel?
The answer lives in group theory.

Alice
secret
keys
Bob
Eve
✦ ✦ ✦

The Mathematics Behind the Lock

Every time you see https:// in your browser, your computer uses a protocol built on abstract algebra. The security relies on a problem called the Discrete Logarithm Problem.


Cyclic Groups

A group is cyclic if a single element g generates every element by repeated multiplication. Every element is some power of g.

The group (Z/pZ)*

When p is prime, the set {1, 2, ..., p-1} under multiplication mod p forms a cyclic group of order p-1. The star excludes 0, which has no multiplicative inverse.

Lagrange's Theorem

If G is a finite group and H is a subgroup, then |H| divides |G|. This directly determines how hard the DLP is: a larger group means a harder problem.

The DLP

Given prime p, generator g, and value h: find k such that gk is congruent to h mod p. Computing gk is easy. Finding k from gk is hard.

Forward (easy): given k, compute gk mod p → logarithmic time
Backward (hard): given gk mod p, find k → search up to p-1 values

Group order = p-1 (Lagrange) → large p = large search space = hard DLP
Why must p be prime? Composite numbers do not guarantee every nonzero element has a multiplicative inverse. Primality ensures (Z/pZ)* is a group. Without it, the protocol breaks.

Diffie-Hellman Key Exchange

Alice and Bob want to share a secret key over a public channel where Eve can see every message. Diffie and Hellman's 1976 protocol makes this possible.

Step 01
Public Setup
Choose prime p
and generator g
of (Z/pZ)*
both public
Step 02
Private Keys
Alice picks secret a
Bob picks secret b
never shared
with anyone
Step 03
Public Keys
A = ga mod p
B = gb mod p
sent openly
Eve sees both
Step 04
Shared Secret
Alice: Ba mod p
Bob: Ab mod p
both equal
gab mod p ✓

Why do they get the same answer?

Because exponentiation commutes: (ga)b = gab = (gb)a. Alice computes Ba = gab. Bob computes Ab = gab. Same result, never transmitted.

Why can't Eve recover the secret? Eve sees p, g, A = ga mod p, and B = gb mod p. Finding a from ga mod p is exactly the Discrete Logarithm Problem. Computationally infeasible for large p.

Concrete example (p = 23, g = 5)

Alice: secret a = 6 → A = 56 mod 23 = 8 (sent publicly)
Bob: secret b = 15 → B = 515 mod 23 = 19 (sent publicly)

Alice: Ba mod p = 196 mod 23 = 2
Bob: Ab mod p = 815 mod 23 = 2

Shared secret = 2   never transmitted ✓

Live Key Exchange

Edit values and press Exchange Keys.
Alice's key flies to Bob. Bob's flies to Alice.

Bob
Receiver
23
5
press Exchange Keys
press Exchange Keys
LOCKED
Public channel
p=23 g=5
A=? B=?
⚠ Eve watches
Waiting for exchange...
Alice
Sender
press Exchange Keys
press Exchange Keys
✦ Shared Secret ? Both computed gab mod p independently   Eve cannot recover this from p, g, A, B alone
4 / 6

The Brute Force Attack

Same protocol. Same attack. The only difference is p. Watch what happens to Alice, Bob, and Eve.

Small Group (p = 23)   Insecure
Alice
calm
Waiting...
Eve
watching
Watching the channel...
Press Run Attack to begin
Click Run Attack to watch the brute force search in real time.
Bob
calm
Waiting...
Large Group (p = 231 - 1)   Secure
Alice
calm
Waiting...
Eve
watching
Watching the channel...
Press Show Secure to begin
Click Show Secure to see what Eve faces with a large prime.
Bob
calm
Waiting...
The takeaway: Security is a consequence of group size. Lagrange's theorem tells us the order of (Z/pZ)* is exactly p-1. A 2048-bit prime gives a group with ~10616 elements. No computer running until the end of the universe could search that space.

The Real World Impact

"The security of the internet depends on a single mathematical fact: computing gk is easy, but finding k from gk is hard. That fact comes from group theory."

Every time you shop online, message a friend, or log into a website, the Diffie-Hellman protocol (or its descendants) is protecting your data. Here is how the abstract algebra you studied connects to the real world.

🔐

TLS/HTTPS

Every https connection uses a key exchange based on DH or ECDH (elliptic curve variant). When you see the padlock in your browser, this protocol ran in milliseconds.

💬

Signal / WhatsApp

End-to-end encryption in modern messaging apps uses the Double Ratchet algorithm, which combines DH key exchange with symmetric encryption for forward secrecy.

💳

Financial Systems

Credit card transactions, banking APIs, and cryptocurrency wallets all rely on DLP-based cryptography. Your payment data is protected by Lagrange's theorem.

🛰️

SSH & VPN

Secure shell connections and virtual private networks use DH for the initial handshake to establish session keys. Every time you SSH into a server, this math runs.

⚡

Elliptic Curves

Modern systems use ECDH: DH on elliptic curve groups instead of (Z/pZ)*. Smaller keys, same hardness. The group theory is identical, just a different group.

🔮

Post-Quantum

Quantum computers could break DLP. NIST has standardized post-quantum algorithms. The math shifts from DLP to lattice problems, but the group theory remains central.

A Brief History

1976
Diffie & Hellman publish "New Directions in Cryptography"
The paper that invented public-key cryptography. Introduced the key exchange and the DLP.
1977
RSA invented
Rivest, Shamir, Adleman build on the same hardness assumptions with a different mathematical structure.
1985
Elliptic Curve Cryptography proposed
Koblitz and Miller independently propose using elliptic curve groups. Smaller keys, same security.
1994
Shor's algorithm threatens DLP
Peter Shor shows a quantum computer could solve DLP in polynomial time. The race for post-quantum crypto begins.
2022
NIST standardizes post-quantum algorithms
The next generation of cryptography. Group theory still central, but now over lattices and other structures.

Lagrange's theorem. Cyclic groups. Quotient groups. Homomorphisms.
These are not just theorems in a math class.
They are the reason the internet is safe.