Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
    
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
    
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.