# IST360 - RSA Encryption Example

Document Sample

```					                                      RSA Encryption Example

The RSA encryption process has been a standard since 1977 and it continues to provide a solid level of
protection for data transfer. Its soul foundation is based on mathematic functions that work with
factoring and modulus of large integers. The design has proved itself over time to be highly secure.
The encryption process is asymmetrical, meaning there are two sets of keys, one public and one private.
This document provides a simplistic working example of how the RSA encryption process would be
utilized to encrypt one small integer.
Building the keys:
1) The first step is to choose two different prime numbers which we’ll name p and q. Normally
these prime numbers would be randomly generated and would be quite large. These numbers
would then be destroyed immediately after the product of the two numbers is determined. For
this example we will use two small values:
p = 5 and q = 11
2) To find the product we multiply p*q to find our first public key value of n. The value n will also
appear in our private key.
n= p*q
n = 55
3) Next we compute the totient or Phi function of p and q. We do this by subtracting 1 from each
and then calculating the product.
m = (p – 1) * (q – 1)
m = 4 * 10
m = 40
* Note – the following steps (4 and 5) are usually handled with the extended Euclidean algorithm. Our
method will be far more rudimental (hit or miss).
4) Next we need to find an integer that is greater than 1 and is coprime to m - we’ll call it “e”.
(coprime to m means no shared factors). e is the second and final value we need to create our
public key. We do this by a hit or miss method starting with the integer 2. (note gcd = greatest
common divisor)
The formula is:                        gcd(e, m) = 1
So let’s plug away… if e = 2 then gcd(2, 40) = 2 (no – 2 and 40 have common factors)
if e = 3 then gcd(3, 40) = 1 (yes – 3 and 40 don’t have common factors)
e=3
5) Step five will provide the remaining value needed for the creation of the private key (d). Now
we go through a process that has us finding a common factor (somewhat the reverse of step 4).
For the value of i we use an integer and we’ll start another hit or miss method starting with 0:
The formula is: d = (1 + im) / e
Rewritten as:      if i = 0 then d = (1+ (0*40)) /3       (no –3 is not a factor of 1)
if i = 1 then d =41/3                  (no – 3 is not a factor of 41)
if i = 2 then d =81/3                  (yes – 3 is a factor of 81)
d = 27

So our public key contains: n = 55 and e = 3 and our private key contains: n = 55 and d = 27

1
RSA Encryption Example

Now that we have created both a public and private key, let’s go through the process of encrypting and
decrypting a small integer using our keys. Let’s encrypt the number 4 (our number must be less than the
value of either p or q). Remember, when text is encrypted or decrypted it is done based on the ASCII
value of the characters. Therefore, all cryptography will be done on numeric values. We’ll consider the
ASCII conversion as already having been done for our examples. The value of 4 relates to the ASCII
value of EOT (end of transmission).

Encryption:

6) Remember to encrypt a message that is not a digital signature we use our public key. The
formula to do so follows (z = the integer that is to be encrypted, e & n from our public key):
e
c = z mod n
3
= 4 mod 55
= 64 mod 55 (calculate this using the scientific calculator in windows)
c = 9 (or divide 55 into 64 1 time with a remainder of 9)

So, using our current set of keys the number 4 is sent across to it’s destination as the number 9 – who
would have guessed?

Decryption:

7) The decryption process usually deals with exponents that are sufficiently large that a hit or miss
method typically would not work. Most calculators cannot handle very large exponents either.
If you are dealing with a value larger than your calculator can handle, try the following URL
(courtesy of the U of Minnesota): Then we can find u (the decrypted value of c), using our
private key that holds the values of d and n.
http://www.math.umn.edu/~garrett/crypto/a01/FastPow.html

d
u = c mod n
27
= 9 mod 55
= 58149737003040059690390169 mod 55 (via windows scientific calculator)
u=4

Yahoo, our decryption worked!

2

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 23 posted: 5/2/2011 language: English pages: 2