solving ax +b mod p = y

1.5k Views Asked by At

How do I solve ax+b mod p = y, with p being prime?

What I have gotten so far is ax = y - b (mod p)

x = (y-b)/ (a^(p-2)) 

a^p-2 being the multiplicative inverse of p. This is derived by using a^(p-1) = 1 mod p

I solved it using Fermat little theorem but I cannot seem to get back the original $x$. Am I doing something wrong here?

1

There are 1 best solutions below

6
On BEST ANSWER

You have to solve $ax\equiv y-b(mod$ $p)$ the fact that $p$ is prime implies $gcd(a,p)=1$ and then the congruence $az\equiv 1 (mod$ $p)$ has a solution let $r$ be that solution.

We have $ax\equiv y-b(mod$ $p) \iff rax\equiv r(y-b)(mod$ $p)$ but $ra\equiv 1 (mod$ $p)$ so $rax\equiv x(mod$ $p)$ and the solution is $x\equiv r(y-b)(mod$ $p)$.