Congruence modulo respects the rules of addition, subtraction and multiplication:
Extended Euclidean Algorithm eGCD:
Input: Integers with .
Output: with and .
If divides return ;
Else compute integers with and ,
Set (note that ),
Return .
The Extended Euclidean algorithm gives as the multiplicative inverse of , and as the multiplicative inverse of when .
To compute :
exp(a, b, N) {
t = 1
x = a
while (b > 0) {
if (b is odd) {
t = [t*x mod N]
b = b-1
}
x = [x^2 mod N]
b = b/2
}
return t
}
Running Time of this algorithm is polynomial in .
— Mar 14, 2023
Made with ❤ at Earth.