# General Exponential modular equation

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)?

-
It is a hard problem, discrete logarithm. As far as I know, one can do better than plain brute force, but no efficient general algorithm is known. –  Daniel Fischer Oct 5 '13 at 18:12
How much hard,can you suggest some heuristic etc.what if everything falls into lets say 32 bit range. –  Amit Oct 5 '13 at 19:16

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.