Linear Congruences

Example: Solve 13x 25 (mod 32).

First we check to see that 13 and 32 are relatively prime; gcd(13,32) = 1. (Actually, this is obvious since 13 is a prime number).

Next use the Euclidean algorithm to find an inverse of 13 modulo 32:

FORWARD                  BACKWARD
---------------          --------------
32 = 2 * 13 + 6          1 = 13 − 2*6
13 = 2 *  6 + 1            = 13 − 2*(32−2*13)
 6 = 6 *  1 + 0            = −2*32 + 5*13

So 5 is an inverse of 13 modulo 32.