how can we use mathematica for POLLARD RHO ALGORITHM to compute the discrete logarithm problem in Zp^*

algorithem is

LetGbe a cyclic group of orderp, and given , and a partition , let be a map

and define maps and by

Inputsaa generator ofG,ban element ofGOutputAn integerxsuch thatax = b, or failureany help would be appreciated.

- Initialise
a0← 0b0← 0x0← 1 ∈Gi← 1xi←f(xi-1),ai←g(xi-1,ai-1),bi←h(xi-1,bi-1)x2i←f(f(x2i-2)),a2i←g(f(x2i-2),g(x2i-2,a2i-2)),b2i←h(f(x2i-2),h(x2i-2,b2i-2))- If
xi=x2ithen

r←bi-b2i- If r = 0 return failure
- x ←
r -1(a2i-ai) modp- return x
- If
xi≠x2itheni←i+1, and go to step 2

the problem i don't know how to use if anf else in mathematica for many conditions.