You are on page 1of 2

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.

Step 2. Find e so that e is relatively prime to (p-1)*(q-1).


For my p and q, (p-1)*(q-1) = 12*18 = 216. I choose e = 11.

(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

The encrypted message sent to me is c = 201.

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

= 102 mod 247, so my message is 102

You might also like