Your privacy choices

KiwiBee uses optional Google Analytics, Google Ads, and Meta Pixel cookies to understand adult visitors, measure completed sign-ups, and improve campaigns. Essential cookies always stay on. OpenAI’s ChatGPT Ads Pixel also measures page views and completed enquiries after advertising consent, and may use hashed contact details for matching. Privacy policy

Skip to main content

Cryptography & Key Exchange

About this simulation

Cryptography & Key Exchange demystifies the mathematics protecting modern internet security. Three illuminated stations represent Alice (left), Eve the Eavesdropper monitoring the public channel (center), and Bob (right). In Diffie–Hellman mode, Alice mixes her secret integer a with the public generator g and prime modulus p to send A = gᵃ mod p across the bridge, while Bob sends B = gᵇ mod p. Even though Eve intercepts g, p, A, and B on her modular arithmetic clock ring, she faces the hard Discrete Logarithm Problem, whereas Alice computes Bᵃ mod p and Bob computes Aᵇ mod p to unlock the exact same glowing shared secret S = gᵃᵇ mod p. Switching to RSA mode shows asymmetric encryption C = Mᵉ mod n and decryption M = Cᵈ mod n.

What students can explore

  • Drag or click Alice's blue private key crystal (a) or Bob's green private key crystal (b) and verify that both top vaults always light up with the exact same Shared Secret number and color!
  • Inspect Eve's Public Channel readout in the center to see everything crossing the wire (g, p, A, B), and notice why knowing gᵃ mod p does not directly reveal a.
  • Switch Prime modulus p between 23, 19, and 29 and watch the central Modular Clock hand jump to the new remainder S mod p.
  • Change Protocol to RSA Public/Private Padlock and adjust Alice's message M to watch it encrypt into ciphertext C = M³ mod 33 over the public bridge and decrypt back to M at Bob's station.
  • Drag Eve's red interceptor orb in the center to scrub the travelling public courier packets back and forth between Alice and Bob.

Learning objectives

  1. 1Trace the four steps of the Diffie–Hellman key exchange using modular exponentiation gᵃ mod p and gᵇ mod p.
  2. 2Prove algebraically why Alice and Bob arrive at the same shared secret: (gᵇ)ᵃ mod p = (gᵃ)ᵇ mod p = gᵃᵇ mod p.
  3. 3Explain why modular exponentiation acts as a one-way trapdoor function (easy forward, hard to invert via discrete logarithms).
  4. 4Contrast symmetric key establishment (Diffie–Hellman) with asymmetric public/private padlock encryption (RSA).

Questions teachers ask

How can Alice and Bob agree on a secret key when Eve sees every message they send?

They never send their private numbers a or b. Instead, they send the mixed modular results A = gᵃ mod p and B = gᵇ mod p. Because raising to a power modulo p wraps around the clock ring repeatedly, Eve cannot easily undo A to find a, yet Alice and Bob can each apply their own secret power to the other's public number to reach gᵃᵇ mod p.

What is the Discrete Logarithm Problem?

Computing gᵃ mod p is fast even for 2048-bit numbers, but given g, p, and the remainder A = gᵃ mod p, finding the exponent a requires searching through an astronomical number of possibilities when p is a large prime.

Why does this simulation use small primes like p = 23 instead of huge primes?

Small primes like p = 23 let you verify every calculation by hand (for example, 5⁶ mod 23 = 15625 mod 23 = 8). Real TLS connections use the exact same equation with primes hundreds of digits long so Eve cannot brute-force them.

How does RSA differ from Diffie–Hellman?

Diffie–Hellman lets two parties jointly create a shared secret key. RSA is an asymmetric padlock: Bob publishes a public lock (e, n) that anyone like Alice can snap shut on a message (C = Mᵉ mod n), while only Bob holds the private key d needed to open it (M = Cᵈ mod n).

Embed this simulation

Drop it into your LMS, blog, or class site — free.

<iframe src="https://kiwibee.io/en/simulations/public-key-cryptography-diffie-hellman-3d-simulation/embed" title="Cryptography &amp; Key Exchange | KiwiBee" loading="lazy" allowfullscreen style="width:100%;height:min(70vh,620px);min-height:420px;border:0;border-radius:16px"></iframe>

Continue exploring

Bring interactive science into your classroom

KiwiBee's free teacher workspace brings lesson planning, worksheets, classroom tools, and gradebook together in one place.

Start free and create your first class

or explore the teacher workspace →