Calculate discrete logarithm

From the % operator I'm assuming that you are working with integers.

You are trying to solve the Discrete Logarithm problem. A reasonable algorithm is Baby step, giant step, although there are many others, none of which are particularly fast.

The difficulty of finding a fast solution to the discrete logarithm problem is a fundamental part of some popular cryptographic algorithms, so if you find a better solution than any of those on Wikipedia please let me know!


This isn't a simple problem at all. It is called calculating the discrete logarithm and it is the inverse operation to a modular exponentation.

There is no efficient algorithm known. That is, if N denotes the number of bits in m, all known algorithms run in O(2^(N^C)) where C>0.

Tags:

Algorithm

Math