next up previous
Next: Up: Previous:

Pseudocode

ModularLinearEquationSolver(a, b, n) $\;\;\;\;\;$; O(lgn + gcd(a,n))
$\;\;\;\;\;$(d, x', y') = Extended-Euclid(a, n) $\;\;\;\;\;$; arithmetic operations
$\;\;\;\;\;$if (d $\mid$ b)
$\;\;\;\;\;$then x0 = x'(b/d) mod n
$\;\;\;\;\;$ $\;\;\;\;\;$for i = 0 to d-1
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$print (x0 + i(n/d)) mod n
$\;\;\;\;\;$else print ``no solutions''

Note: Solving ax $\equiv$ 1 (mod n) gives \({\rm a}^{-1}\) mod n (only one solution).


next up previous
Next: Up: Previous: