Unformatted text preview: (" << b << ") * " << v << " = " << gcd << endl; if (gcd == 1) cout << "the inverse of " << v << " mod " << u << " is: " << u  b << endl; return 0; } I’m not going to prove that it works or give the theory behind it. Details can be found in [863], or in any of the number theory texts previously listed. The algorithm is iterative and can be slow for large numbers. Knuth showed that the average number of divisions performed by the algorithm is: .843*log2(n) + 1.47 Solving for Coefficients
Euclid’s algorithm can be used to solve this class of problems: Given an array of m variables x1, x2,...xm, find an array of m coefficients, u1, u2...um, such that u1*x1 + ...+ um*xm = 1 Fermat’s Little Theorem
If m is a prime, and a is not a multiple of m, then Fermat’s little theorem says am 1 a 1 (mod m) (Pierre de Fermat, pronounced “Fairma, ” was a French mathematician who lived from 1601 to 1665. This theorem has nothing to do with his last theorem.) The Euler Totient Function
There is another method for calculating the inverse modulo n, but it’s not always possible to use it. The reduced set of residues mod n is the subset of the complete set of residues that is relatively prime to n. For example, the reduced set of residues mod 12 is {1, 5, 7, 11}. If n is prime, then the reduced set of residues mod n is the set of all numbers from 1 to n 1. The number 0 is never part of the reduced set of residues for any n not equal to 1. The Euler totient function, also called the Euler phi function and written as Æ(n), is the number of elements in the reduced set of residues modulo n. In other words, Æ(n) is the number of positive integers less than n that are relatively prime to n (for any n greater than 1). (Leonhard Euler, pronounced “Oiler, ” was a Swiss mathematician who lived from 1707 to 1783.) If n is prime, then Æ(n) = n 1. If n = pq, where p and q are prime, then Æ(n)...
View
Full Document
 Fall '10
 ALIULGER
 Cryptography, Bruce Schneier, Applied Cryptography, EarthWeb, Search Search Tips

Click to edit the document details