You are on page 1of 4

RSA Algorithm Examples (with some more

detailed solutions)
Dr. Holmes
November 28, 2006

In each example, the modulus N and the encryption exponent r are given.
A message to encrypt and a message to decrypt are given (just numbers!) In
each part, find the decryption exponent s, encrypt the message to encrypt
and decrypt the message to decrypt. Answers are given!
More detailed solutions are given in parts 1 and 2.
The second example is perhaps small enough to be a test question. The
first one is certainly too large to be a test question but notice that it is a
doable homework problem; I show you how to do all the steps with a stupid
calculator (as long as it can handle tens of millions; even my calculator in
floating point gave me trouble in one place).
I may add some Chinese Remainder Theorem examples later.
1. N = 851; r = 5
encrypt 24.
decrypt 111.
Solutions: the encryption of 24 is 668. The decryption exponent is 317.
The decryption of 111 is 148..
Detailed Solutions:
For the first part, we need to compute 245 mod851.
245 = 7962624; 7962624 − (9356)(851) = 668; the answer is 668.
To do the second part, we first need to find the encryption exponent.
N = 851 = (23)(37) so E = (22)(36) = 792. gcd(5, 792) = 1 as desired.
We need to find the multiplicative inverse of r = 5 mod 792; this will
be our encryption exponent s.

1
The idea is to use the Euclidean algorithm to solve 5x + 792y = 1; the
value of x that we find is the multiplicative inverse we are looking for.
792 − 158(5) = 2; 5 − 2(2) = 1; so 5 − 2(798 − 158(5)) = 1; there are 1
+ 158(2) 5’s here and −2 792’s: 317(5)-2(792) = 1. So the reciprocal
of 5 mod 792 is 317.
317, 158, 79, 39, 19, 9, 4, 2 are the sequence of powers we need to
compute (dividing by 2 each time and throwing away the remainder).
Now we set out to compute 111371 mod851 (this will be the decryption
we want).
1112 = 12321; 12321 − (14)(851) = 407
1114 = (1112 )2 ; 4072 = 165649; 165649 − (194)(851) = 555
1119 = (1114 )2 (111); 5552 (111) = 34190775;34190775 − (40177)(851) =
148
11119 = (1119 )2 (111); 1482 (111) = 2431344; 2431344 − (2857)(851) =
37
11139 = (11119 )2 (111); 372 (111) = 151959; 151959 − (178)(851) = 481
11179 = (11139 )2 (111); 4812 (111) = 25681071; 25681071−(30177)(851) =
444
111158 = (1117 9)2 ; 4442 = 197136; 197136 − 231 ∗ 851 = 555
111317 = (111158 )2 (111); 5552 (111) = 34190775;34190775−(40177)(851) =
148
The desired decryption is 148.
I think the repetition of part of the calculation has something to do
with the fact that we actually have a “bad” message: 111 has 37 as a
factor (one of the factors of N )! But our decryption procedure works
nonetheless.

2. an example with small numbers: N = 247; r = 7


encrypt 100.
decrypt 120.
Solutions: the encryption of 100 is 35. The decryption exponent is 31.
The decryption of 120 is 42.

2
Detailed Solutions:
to compute 1007 mod247
first compute 1003 mod247: 1000000-4048(247) = 144.
now 1007 = ((1003 )2 )(100) will be equivalent to 1442 (100) or 2073600
and 2073600 − (8395)(247) = 35.
So the answer to the first part is 35.
To find the decryption exponent: N = 247 = (13)(19) so E = (12)(18) =
216 and the decryption exponent s will be the multiplicative inverse
of r = 7 mod 216. gcd(7, 216) is 1 as require: we need to solve
7x + 216y = 1, and x will be the multiplicative inverse we are looking
for.
216-30(7) = 6
7-6 = 1
so 7 - (216-30(7)) = 1, and collecting multiples of 7 and 216 we have
(7)(31)-(216)(1) = 1.
To decrypt 120, we need to compute 12031 mod247.
successive divisions by 2 give 31, 15, 7, 3 as powers to compute.
1203 = 1728000; 1728000 − 6995(247) = 235
1207 = (1203 )2 (120); 2352 (120) = 6627000; 6627000 − (26829)(247) =
237 (I ran into a problem with floating point arithmetic: my calculator
rounded the quotient up to 26830 here; but when I saw the negative
remainder the correction was easy).
12015 = (1207 )2 (120); 2372 (120) = 6740280; 6740280 − 27288(247) =
144
12031 = (1201 5)2 (120); 1442 (120) = 2488320; 2488320 − 10074(247) =
42
and 42 is the answer we want.

3. Here’s one with r = 3. Only a quarter of possible values of N let us


use r = 3; if you can explain why I’ll be impressed. This doesn’t rely
on anything you don’t know, you just have to think carefully.
N = 391; r = 3

3
Encrypt 123.
Decrypt 13.
Solutions: The encryption of 123 is 98. The decryption exponent is
235. The decryption of 13 is 225.

4. N = 1147; r = 17 (17 is not that hard an exponent to compute; do you


see why?)
Encrypt 42.
Decrypt 96. (of course the answer should be 42!)
Solutions: the encryption of 42 is 96. The decryption exponent is 953
(OK, that’s a bit nasty). The decryption of 96 is of course 42.

5. This is just for those of you with access to technology (Maple, a TI89,
whatever).
N = 2360221; r = 5
Encrypt 1234.
Decrypt 4321.
Solution: The encryption of 1234 is 1637411. The decryption exponent
is 942797. The decryption of 4321 is 76152.

You might also like