applied cryptography - protocols, algorithms, and source code in c

For example j7 143 j7 11j7 13 1 1 1

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ome primes can appear more than once. For example, p1 might be equal to p2 .) In other words, a number (less than the product of some primes) is uniquely identified by its residues mod those primes. For example, use 3 and 5 as primes, and 14 as the number. 14 mod 3 = 2, and 14 mod 5 = 4. There is only one number less than 3*5 = 15 which has those residues: 14. The two residues uniquely determine the number. So, for an arbitrary a < p and b < q (where p and q are prime), there exists a unique x, where x is less than pq, such that x a a (mod p), and x a b (mod q) To find this x, first use Euclid’s algorithm to find u, such that u*q a 1 (mod p) Then compute: x = (((a - b)*u) mod p)*q + b Here is the Chinese remainder theorem in C: /* r is the number of elements in arrays m and u; m is the array of (pairwise relatively prime) moduli u is the array of coefficients return value is n such than n == u[k]%m[k] (k=0..r-1) and n < m[0]*m[1]*...*m[r-1] */ /* totient() is left as an exercise to the reader. */ int chinese_remainder (size_t r, int *m, int *u) { size_t i; int modulus; int n; modulus = 1; for (i=0; i<r; ++i) modulus *= m[i]; n = 0; for (i=0; i<r; ++i) { n += u[i] * modexp(modulus / m[i], totient(m[i]), m[i]); n %= modulus; } return n; } The converse of the Chinese remainder theorem can also be used to find the solution to the problem: if p and q are primes, and p is less than q, then there exists a unique x less than pq, such that a a x (mod p), and b a x (mod q) If a e b mod p, then x = (((a - (b mod p))*u) mod p)*q + b If a < b mod p, then x = (((a + p - (b mod p))*u) mod p)*q + b Quadratic Residues If p is prime, and a is greater than 0 and less than p, then a is a quadratic residue mod p if x2 a a (mod p), for some x Not all values of a satisfy this property. For a to be a quadratic residue modulo n, it must be a quadratic residue modulo all the prime factors of n. For example, if p = 7, the quadratic residues are 1, 2, and 4: 12 = 1 a 1 (mod 7) 22 = 4 a 4 (m...
View Full Document

This note was uploaded on 10/18/2010 for the course MATH CS 301 taught by Professor Aliulger during the Fall '10 term at Koç University.

Ask a homework question - tutors are online