I have some trouble implementing a simple algorithm for solving the DLP in F_p^* using Mathematica. The algoritm should look as follow:
p = RandomPrime[{10^2, 10^3}]
g = PrimitiveRoot[p]
h = Mod[RandomInteger[{10^2, 10^3}], p]
Naive = Function[{g, p, h},
Module[{i, st, b, c, res}, st = 0; b = 1; c = Mod[h, p];
For[i = -1, st == 0 && i < p - 1, i++, If[b == c, st = 1];
b = Mod[b*g, p]];
If[st == 0, res = "no solution", res = i];
res]]
The only output I get is:
739
3
473
Function[{g, p, h}, Module[{i, st, b, c, res}, st = 0;
b = 1;
c = Mod[h, p];
For[i = -1, st == 0 && i < p - 1, i++, If[b == c, st = 1];
b = Mod[b g, p]];
If[st == 0, res = "no solution", res = i]; res]]
How can I implement this correctly, so the DLP can be solved?
Naive[g, p, h]
give you the result? (also it's best practices to not use names with a capital letter as the first letter) $\endgroup$