Professional Documents
Culture Documents
RSA Example
RSA Example
Set up system.
Step 1. Pick two large primes p and q (really should be 150 digits or so)
We pick 13 and 19. Calculate N = p*q. N = 13*19 = 247.
(e, N) is the public key. So I let everyone know my public key is (11, 247)
Step 3. Find private key. Find a number d so the e*d = 1 mod(p-1)*(q-1). For
me this means that 11*d = 1 mod 216. It turns out that d = 59 works.
(11*59 = 649 and 649 divided by 216 is 3 with remainder 1)
I keep my d = 59 secret!
Using my code
Someone else wants to send me a message. The message is changed
into a number, say m = 102. The sender encrypts m by the formula
e 11
c = m mod N. For this message, using my public key we need to compute c = 102 mod 247
computation:
1
102 = 102 mod 247
2
102 = 30 mod 247
4 2
102 = 30 = 159 mod 247
8 2
102 = 59 = 87 mod 247
11 8 2 1
102 = 102 * 102 * 102 = 87 * 30 * 102 = 201 mod 247
Reading my message
d 59
Use the formula m = c mod N. I need to find m = 201 mod 247
computation:
1
201 = 201 mod 247
2
201 = 140 mod 247
4 2
201 = 140 = 87 mod 247
8 2
201 = 87 = 159 mod 247
16 2
201 = 159 = 87 mod 247
32 2
201 = 87 = 159 mod 247
59 32 16 8 2 1
201 = 201 * 201 * 201 * 201 * 201 = 159 * 87 * 159 * 140 * 201 mod 247