Home / Calculators / Discrete Logarithm Solver
Free online tool

Discrete Logarithm Solver

Search for x where g^x ≡ h (mod p) within practical teaching-size limits. Processing takes place locally in your browser.

Start using

Discrete Logarithm Solver

Finds the smallest nonnegative exponent x such that g^x is congruent to h modulo p by checking x from 0 through p-1. Defaults are g=2, h=8, p=13, which return x=3 because 2^3 mod 13 = 8. Inputs g,h and p must be integers; p is limited to 2..1,000,000.

The search starts with value 1 for exponent 0 and repeatedly updates value=(value*g) mod p. h is normalized modulo p, so negative or above-modulus h values are compared by their residue. If no match is found during p checks, the tool reports no solution.

The modulus is not required to be prime and the tool does not prove that g generates a multiplicative group. With non-coprime values the sequence can enter a shorter cycle, but the bounded exhaustive scan still returns the first checked exponent when a match exists.

This is an O(p) educational exhaustive search, not baby-step giant-step, Pollard rho or a cryptographic attack service. The one-million modulus ceiling limits main-thread work; real cryptographic moduli are intentionally infeasible here. JavaScript Number arithmetic is used within the imposed range.

Calculation runs locally without server or AI. Enter plain integers, calculate and verify the congruence independently for consequential work. The result is not a private-key recovery claim, security assessment or evidence that a cryptographic group is weak.

Enter nonempty safe integers for g and h: each must be between -9007199254740991 and 9007199254740991. The modulus p must be an integer from 2 to 1000000. The base and target are reduced modulo p before the search.

Processing takes place locally in your browser.