Discrete logarithm calculator

The discrete logarithm problem is to find the exponent in the expression BaseExponent = Power (mod Modulus).

This applet works for both prime and composite moduli. The only restriction is that the base and the modulus, and the power and the modulus must be relatively prime.

In this version of the discrete logarithm calculator only the Pohlig-Hellman algorithm is implemented, so the execution time is proportional to the square root of the largest prime factor of the modulus minus 1. The applet works in a reasonable amount of time if this factor is less than 1017.

I will add the index-calculus algorithm soon. This algorithm has subexponential running time.


You can also enter expressions that use the following operators and parentheses:

You can use the prefix 0x for hexadecimal numbers, for example 0x38 is equal to 56.

The exponentiation symbol is not present in some mobile devices, so two asterisks ** can by typed as the exponentiation operator.

Example: Find the number n such that 7n ≡ 23 (mod 43241).

Type 7 in the Base input box, 23 in the Power input box and 43241 in the Mod input box. Then press the button named "Discrete logarithm".

The result is 3360 + 3930 k. As a check you can compute 73360 ≡ 23 (mod 43241) and 73930 ≡ 1 (mod 43241).

Source code

You can download the source of the current program and the old sum polynomial factorization applet from GitHub. Notice that the source code is in C language and you need the Emscripten environment in order to generate Javascript.

Written by Dario Alpern. Last updated 31 July 2016.

If you find any error or you have a comment, please fill in the form.