3

Can anyone tell me how to solve this equation for lowest $x$

$$a^x \equiv n \mod m$$

other than trying every possible $x$ from $0$ to $m-1$ ($m$ is prime)?

dibyendu
  • 539
Amit
  • 31

1 Answers1

2

This is known as the discrete logarithm problem, and it's a hard problem. By hard, I mean that it's an NP (in the P$\neq$NP sense) problem.

So the short answer is that for anything of any reasonably small size, you should just do trial division.

For slightly larger ones, there are a variety of slightly-faster-but-still-slow algorithms, such as a variant of Pollard's rho algorithm for factoring, or the cutely titled baby-step giant-step algorithm.