Discrete Logarithm Subroutine Calculator

Solve discrete logs with brute force or giant-step. Review powers, orders, collisions, and method details. Download outputs and visualize modular patterns with simple charts.

Calculator Input

This page is best for modest educational inputs and bounded searches. Very large cryptographic cases are outside the practical scope of a browser page.

Example Data Table

Base g Target h Modulus n Smallest x Check
5 8 23 6 5^6 ≡ 8 (mod 23)
2 18 29 11 2^11 ≡ 18 (mod 29)
3 13 17 4 3^4 ≡ 13 (mod 17)

Formula Used

The calculator solves the modular equation g^x ≡ h (mod n). Here, g is the base, h is the target residue, n is the modulus, and x is the unknown exponent.

Brute force tests exponents one by one until a match appears or the chosen bound ends. This gives transparent residue tracking and is useful for teaching and verification.

Baby-step giant-step rewrites x as x = im + j, where m is about the square root of the search bound. It stores baby steps g^j and compares them with transformed giant steps h(g^-m)^i.

When gcd(g, n) = 1, the base belongs to the multiplicative unit group modulo n. In that case, the multiplicative order of g helps explain repeated solutions because exponents differ by multiples of that order.

How to Use This Calculator

  1. Enter the base g, target h, and modulus n.
  2. Choose a maximum exponent range for the bounded search.
  3. Select Auto, Brute Force, or Baby-step Giant-step.
  4. Set how many points you want in the plot.
  5. Set how many rows you want in the residue table.
  6. Submit the form to see the result above the calculator.
  7. Review the summary, residue plot, and residue table.
  8. Use the CSV and PDF buttons to export the output.

Frequently Asked Questions

1. What is a discrete logarithm?

A discrete logarithm asks for an exponent x such that g^x matches a target residue h modulo n. It is the modular counterpart of ordinary logarithms.

2. Why can the calculator return no solution?

A solution may not exist for the chosen values, or it may exist beyond the selected exponent bound. Some inputs also fall outside the relevant unit structure.

3. When should I use brute force?

Use brute force when you want a transparent educational search, a short exponent range, or a direct residue table showing each tested step.

4. When should I use baby-step giant-step?

Use it for wider bounded searches when the base is invertible modulo n. It reduces search effort by splitting the exponent into smaller matching parts.

5. What does multiplicative order mean here?

The multiplicative order is the smallest positive integer r with g^r ≡ 1 (mod n). It explains periodic repeats in valid exponents.

6. Why are values normalized first?

Normalization replaces negative or large entries with their least nonnegative residues modulo n. That keeps every computation in a consistent modular form.

7. Can I use very large cryptographic numbers?

This page is designed for bounded educational work. Very large cryptographic sizes demand specialized libraries, optimized arithmetic, and much more memory.

8. What do the graph and table show?

They show the residue walk g^x mod n across the selected range. This helps you spot cycles, repeated patterns, and target matches visually.

Related Calculators

extended euclidean calculatorfactor pair generatorlargest prime gap calculatortool for computing prime factorization time complexity

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.