

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


We have observed that the euclidean algorithm can be used to find the GCD of two integers, and hence can be used to
determine if the integer a has a multiplicative inverse in Zm. In this section, we see how we may determine the value
of the inverse if a is invertible.
Recall the euclidean algorithm. For example, recall its use to determine gcd(79, 551).
(a, b) = (551, 79) (a, b) = (79, 77) (a, b) = (77, 2) (a, b) = (2, 1) (a, b) = (1, 0) return(1)
As the gcd of 79 and 551 is 1 , 79 is invertible modulo 551. In fact, the euclidean algorithm can be reversed as follows
to determine the inverse, by keeping a record of the quotient.
i a b qi 0 551 79 6 1 79 77 1 2 77 2 38 3 2 1 2 4 1 0
Now reverse direction and compute an extra pair, (s, t) := (t, s − t ∗ qi).
i a b qi s t 0 551 79 6 39 -38-(39)6 = - 1 79 77 1 -38 1 - (-38)(1)= 2 77 2 38 1 0-(1)(38) =- 3 2 1 2 0 1 4 1 0
What you’ve found is the numbers s and t such that sa + tb = 1. Thus 39 × 551 + (−272) × 79 = 1, and
(−272) × 79 = 1 mod 551 , or 279 × 79 = 1 mod 551 , and 79 −^1 mod 551 = 279.
CSCI 124 and CSCI 297/Vora/GWU 2
gcd and inverse(m, n) /* m > n */
(a, b) := (m, n) /* Initialize */
i = 0; /* Keep track of all quotients */
while (b 6 = 0)
qi := b ab c/* Remember ith^ quotient */
(a, b) := (b, a mod b) /* Reduce problem */
i := i+1 /* Increment count */
}
i := i-1; /* Now i reflects the number of q’s because the last value of i does not correspond to a q*/
/* Now go back up loop to determine inverse */
(s, t) := (0, 1) /* Initialize */
i := i-1 /* Update i */
while (i > 0 )
(s, t) := (t, s − t ∗ qi)
i := i-
}
return(a, (s,t))
Example: Use the generalized euclidean algorithm to determine the decryption key for an affine cipher if the encryp-
tion key is (28, 7) and the modulus is 75 ; that is, the encryption function is eK (x) = 28x + 7 mod 75.
First find 28 −^1 mod 75.
i a b qi 0 75 28 2 1 28 19 1 2 19 9 2 3 9 1 9 4 1 0
Now reverse direction.
i a b qi s t 0 75 28 2 3 -2-(3)(2) = - 1 28 19 1 -2 1 - (-2)(1) = 3 2 19 9 2 1 0-(1)(2) = - 3 9 1 9 0 1 4 1 0