0

I wrote a very simple algorithm to find the discrete logarithm of a certain number, it simply starts at p=1 and increments it until it finds a value of p that satisfies (b^p) % m = x.

The problem I have is that while this algorithm works when there exists a value to the discrete logarithm fo x, I reckon it would loop infinitely if it didn't. Is there s simple stop condition that I can use in my loop to know there is no result?

Thank you

EDIT: I am aware there exists more efficient algorithms but the trial multiplication algorithm is good enough for my use case.

Pop Flamingo
  • 807
  • 1
  • 8
  • 17

0 Answers0