You are on page 1of 2

Cryptography Lab 03: RSA Encryption and Decryption

Lab Objectives:
After this lab, the students should be able to
- Explain the simple concepts of encryption and decryption to protect information in
transmission.
- Explain the concepts of cryptography, symmetric key, public keys and private keys used in
practice.
- Write programs that encrypt and decrypt data files using RSA cryptography algorithm.
Definitions:
Public key encryption is a method where two keys are generated, one to encrypt the message and
another to decrypt the message. The encryption key is available to everyone. That is anyone can
generate an encrypted message for a specific receiver. However, the decrypt key is kept secret.
Only the holders of the decryption key can decrypt the cipher text.
The RSA encryption algorithm was first publicly described by Ron Rivest, Adi Shamir and Leonard
Aldeman in 1978. RSA is a popular public key encryption algorithm. It uses two secret prime numbers
and properties of modulus arithmetic to generate both the public and private keys.
A nice outline of the RSA algorithm and implementation can be found at: http://www.di-
mgt.com.au/rsa_alg.html
More generally, the public key consists of two values: (e, n) where the plain text message, m, is
encrypted (cipher text c) via the following formula:

c=m e mod n

The private key consists of two values (d,n), where the encrypted text c is decrypted by the
following formula
m= cd mod n

These algorithms are based on the theorems of modulus arithmetic.

Outline of work:
You are to create 3 programs:
1. Key generation program
Input:??
Output: integers: public key,
integers: private key
2. Encryption program
Input: integers: public key
string: plain text message
Output
string: encrypted message
3. Decryption program
Input: integers: private key
string: encrypted message
Output: string: plain text message

Key generation program


Generation of the keys is imitated with the selection of two large prime numbers, p and q. A
requirement can sometimes be that the product of these numbers is 1024 bits long. Obviously, the
longer the numbers the more difficult it will be to break this encryption. A suggestion is to pick two
different primes between small ranges, like 137 – 311. Randomly pick a number, test for prime,
increase the number if it is not prime.
The values of the algorithm are built from these two prime numbers.
- n is the product of these two numbers.
n = p*q
- e is built as follows:
• z is the product of one less than each of these two numbers.
z = (p-1)(q-1)
• Choose e such that
1<e<z
And
gcd(e,z) = 1

- Choose d such that


1<d<z
And
ed mod z = 1

- PUBLIC KEY: (e, n)


- PRIVATE KEY: (d, n)

Encryption program
Procedure to encrypt and decipher:
To encrypt a string message M, it is first converted into message blocks M1, M2, …, Mn (each block
can consist of 1 to some number k of characters). Then each message block Mi is mapped to an integer
mi (by an array for example). From mi we calculate the cipher text, ci, as described in Definitions
section. The public key consists of two values: (e, n) where the plain text message, m, is encrypted
(cipher text c) via the following formula:
c=m e mod n

Decryption program
Procedure to encrypt and decipher:
To encrypt a string message M, it is first converted into message blocks M1, M2, …, Mn (each block
can consist of 1 to some number k of characters). Then each message block Mi is mapped to an integer
Pi (by an array for example). From Pi we calculate Cipheri as described in Definitions section: The
public key consists of two values: (e, n) where the plain text message, m, is encrypted (cipher text c)
via the following formula:
m=cd mod n
Note: refer to the above link for more details and hints.

You might also like