Modular arithmetic
All arithmetic happens in ℤ_q, the integers modulo a prime. Results wrap around, so every value stays between 0 and q − 1.
mod qBigIntegerA Java implementation of the Diffie–Hellman key exchange. Two parties each keep a private exponent and publish αX mod q. From what they receive, both compute the same key K, then use it to encrypt and decrypt a message. Recovering a private exponent from the public values is the discrete logarithm problem.
The project shows how two participants can establish a shared secret using public-key cryptography. It implements the Diffie–Hellman key exchange, so a key can be agreed over an insecure channel without either private value ever being sent.
The derived key then drives message encryption and decryption. The program validates every input and offers two ways to explore it: a guided numerical example and an interactive live mode.
Computing αx mod q is fast. Going the other way, recovering x from the result, is the discrete logarithm problem, which is infeasible in practice when q is large.
The worked example from the report, with q = 23 and α = 5. Eve sees every value that crosses the channel. To learn K she would have to solve 5x ≡ 8 (mod 23) for x.
The same computation as Main.runLiveMode(), in your
browser. The ring shows the subgroup ⟨α⟩: if
α is a primitive root, its powers reach every
nonzero residue. If it isn't, most of the ring stays dark.
Every concept below maps to a specific line of the Java implementation.
All arithmetic happens in ℤ_q, the integers modulo a prime. Results wrap around, so every value stays between 0 and q − 1.
mod qBigIntegerThe modulus must be prime so that every nonzero residue has an inverse. Validator runs a probabilistic primality test with certainty 100.
Validator.isPrimeisProbablePrime(100)A primitive root α generates the whole multiplicative group: its powers hit all q − 1 nonzero residues before repeating.
Parameters.getAlphaord(α) = q − 1Square-and-multiply computes α^X mod q in about log₂ X steps, which makes public keys cheap to compute even for huge exponents.
modPowKeyExchangeGiven α, q and Y = α^X mod q, finding X has no known efficient method for well-chosen large primes. This is the hard problem the protocol relies on.
Eve's problemThe shared key is hashed with SHA-256 into 32 bytes and XORed with the message. Because (m ⊕ k) ⊕ k = m, the same operation decrypts.
Encryptor.xorSHA-256
Read the codebase as a directed graph: each vertex is a class and an
edge u → v means u
uses v. Main is the entry point:
it runs the menu and calls modPow itself.
KeyExchange packages the same computation as a reusable
subclass of Parameters, and Utils is an
isolated vertex that the main flow never calls. Select a vertex to
read its source.
Console output from the three test scenarios in the report. Select a screenshot to enlarge it.



Each member owned part of the code and part of the write-up. Select a member to see what they did.
Scope, purpose and how the implementation connects theory with working software.
OpenThe Diffie–Hellman model, its security assumption and a verified numerical example.
OpenClass responsibilities, the five-stage workflow and the two operating modes.
OpenLive mode, input validation and the fixed numerical example, with screenshots.
OpenWhy plain DH needs authentication, and how it compares with ECDH.
OpenWhat was achieved, what was learned and what comes next.
OpenDiffie & Hellman (1976) and the other sources behind the project.
OpenThe final submitted report, embedded and downloadable.
OpenThe report covers the mathematics, the design and every test case. The repository has the complete Java source.