Quadratic modular equation solver

ax² + bx + c ≡ 0 (mod n)

This calculator can solve equations of the form a⁢x² + bx + c ≡ 0 (mod n) where the integer unknown x is in the range 0 ≤ x < n. In particular, it can find modular square roots by setting a = -1, b = 0, c = number whose root we want to find and n = modulus.

You can type numbers or numerical expressions on the input boxes at the left.

The calculator accepts numbers of up to 1000 digits, but notice that the modulus n should be factored (some large numbers cannot be factored in a reasonable amount of time). The factorization engine is the one used in the Elliptic Curve Method factorization applet, that uses the methods ECM and SIQS.

When a is not zero, the number of solutions depends on the number of distinct prime factor of the modulus, so if the modulus has many small prime factors (say more than 14), the program could run out of memory and it will not show any solution.


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.

Source code

You can download the source of the current program and the old quadratic modular equation 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 6 August 2017.

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