Discrete Logarithm Calculator
Find a small integer x such that gˣ ≡ h (mod p) by educational brute force. This educational calculator shows the formula, result, and step-by-step interpretation.
Calculator
What this calculator teaches
The discrete logarithm problem is easy for tiny examples but hard for large cryptographic groups.
Use the result as a learning aid. For classwork, still show the formula and intermediate reasoning so the final answer is not just a black-box number.
What a Discrete Logarithm Means
A discrete logarithm asks for an integer exponent x satisfying gˣ ≡ h (mod p). It is analogous to an ordinary logarithm because x is the unknown exponent, but all arithmetic takes place in a finite modular system. For small teaching examples, the simplest method is to list powers of g, reduce each modulo p, and stop when the residue equals h.
A solution is not guaranteed for every choice of g, h, and modulus. The powers of g generate a subgroup of the nonzero residues, and h must lie in that subgroup. If p is prime and g is a primitive root modulo p, then every nonzero residue occurs among g⁰,g¹,…,g^(p−2), so each nonzero h has a discrete logarithm modulo p−1. If g has smaller order, only some targets can be reached.
| Idea | Rule |
|---|---|
| Target equation | gˣ ≡ h (mod p) |
| Search sequence | 1, g, g², g³, … (mod p) |
| Period | powers repeat according to the order of g |
Real cryptographic systems use enormous groups where brute-force search is infeasible. This page is intentionally educational and suited only to small examples. Efficient algorithms such as baby-step giant-step or Pollard rho are used for larger research examples, while cryptographic security depends on choosing groups where the discrete logarithm problem remains computationally difficult.
Checking a discrete-log answer is easy even when finding it is hard. Once a candidate x is known, compute gˣ mod p and verify that the result equals h mod p. This asymmetry—easy verification but potentially difficult search—is one reason discrete logarithms are important in cryptography.
For a small modulus, also list the cycle of powers of g. The number of distinct nonzero residues before the sequence returns to 1 is the order of g. If the target h never appears in that cycle, there is no solution for that base. If it does appear, all solutions repeat modulo the order of g, so the first occurrence gives the smallest nonnegative answer.
Formula & Symbols
| Concept | Formula or rule |
|---|---|
| Discrete logarithm | gˣ ≡ h (mod p) |
| Brute-force search | try x = 0,1,2,... |
Worked example
Common mistakes
Keep lists comma separated, matrices as rows separated by semicolons, and modular inputs as integers.
Some methods require positive probabilities, valid moduli, independent trials, or small educational input sizes.
If h is outside the subgroup generated by g, no exponent will produce it.
Taking ln(h)/ln(g) does not solve a modular exponent equation because modular reduction changes the structure completely.
FAQ
Related calculators
These links will work after the calculators are registered in the final Math layout update.
Formula Explorer connections
Interpretation: This formula describes an algebraic relationship among variables, functions, equations, roots or sequences. Assumption: Respect the expression’s domain and excluded values. Check roots in the original equation because transformations can introduce extraneous solutions.