Pensador's Blog

Just another pseudointellectual

In public-key Cryptography, especially with the RSA algorithm, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows

x a1 mod m1
x a3 mod m2

x ak mod mk ,

where m1, m2, ..., mk are coprime, i.e. gcd(m1, m2, ..., mk) = 1. How can we solve for x? The solution is quite straight forward, but could involve a fair amount of calculations. I find that breaking down the method into smaller steps makes it easier to find and fix mistakes. By the Chinese Remainder Theorem, the solution to that system of equations is

x = (a1M1y1 + a2M2y2 + ... + akMkyk) mod M ,

where Mi is the product of all m's except for mi

,

yi is the multiplicative inverse of Mi modulo mi

yi Mi-1 mod mi ,

and M = m1 * m2 * ... * mk .

Let us try a numeric example. Here is a system of simultaneous congruences:

x 12 mod 25
x 9 mod 26
x 23 mod 27

We start by calculating M1 and y1:
M1 = m2 * m3 = 26 * 27 = 702
y1 = M1-1 mod m1 = 702-1 mod 25 .

We apply the Extended Euclidean Algorithm to find the multiplicative inverse of 702 relative to 25:
702 = 28 * 25 + 2 → 2 = 702 – 28 * 25
25 = 12 * 2 + 1 → 1 = 25 – 12 * 2
                                = 25 – 12 * (702 – 28 * 25)
                                = 337 * 25 – 12 * 702

Then y1 = 702-1 mod 25 -12 13.

The same calculations can be carried on to find M2 = 675, y2 = 25, M3 = 650 and y3 = 14. Now it is just a matter of plugging in the values into the equation:

x = (a1M1y1 + a2M2y2 + a3M3y3) mod M
= (12*702*13 + 9*675*25 + 23*650*14) mod 17550 470687 14387

To verify our answer we can plug that number back into the system:

470687 mod 25 12
470687 mod 26 9
470687 mod 27 23



Comments - Add yours

#1 by Bernard on Oct 5, 2007 at 9:02 - Reply
Saulo, Thank God you posted this! I spent years trying to figure out the Chinese theorem, and you, in a few seconds, you managed to show me everything I always wanted to know about it! Thanks, you did good in the week of success.
#2 by Pensador on Oct 5, 2007 at 18:22 - Reply
Dear Bernard,

I posted this article with you in mind—I knew how much you would appreciate it.

Regards,
Saulo
#3 by Gabx on Nov 8, 2007 at 20:31 - Reply
What is all this nerdy stuff ? O_o
Why aren't you speaking earthing ?
Add a Comment
You are not logged in. To prevent spamming, posts by unregistered users must be approved before they are published and cannot contain any links.
We strongly suggest you to log in. Don't have an account? Create one now!


Please enter the quoted word below exactly as you see it. It is case sensitive.
"Next"


Allowed tags: <i> <b> <a href="" title=""> <abbr title=""> <acronym title=""> <code>
<blockquote cite=""> <strike>

Poll

Do you have Vista as your main OS?

Yes.
No, but if I buy a new system I will.
No, and I'm not planning to.

Results | Previous polls

Random thought

What difference does it make to the dead, the orphans, and the homeless, whether the mad destruction is wrought under the name of totalitarianism or the holy name of liberty and democracy?

Mahatma Mohandas K. Gandhi (1869-1948)

Ads

Search HotJobs now for jobs
GoDaddy.com $1.99 Domains