Sie sind auf Seite 1von 16

Assignment-1

Public Key Encryption

1
RSA
• RSA (Rivest, Shamir, Adleman)
– developed in 1977
– only widely accepted public-key encryption alg.
– given tech advances need 1024+ bit keys

2
Creating public/private keys
1. Choose two large prime numbers p, q.
(e.g., 1024 bits each)

2. Compute n = pq, z = (p-1)(q-1)

3. Choose e (with e<n) that has no common factors


with z. (e, z are “relatively prime”).

4. Choose d such that ed-1 is exactly divisible by z.


(in other words: ed mod z = 1 ).

5. Public key is (n,e). Private key is (n,d).


PU PR
3
Encryption
0. Given public key (n,e) as computed above
1. To encrypt message m (<n), compute

e
c = m mod n

4
Decryption

0. Given private key (n,d) as computed above

2. To decrypt received bit pattern, c, compute

m = cd mod n

5
Implementation
• Write a program implementing RSA public
key encyption algorithm.
• Your program should do 3 activities:

– Help user for public and private key selection


– Encrypt the given text
– Decrypt the given encrypted text

6
Implementation
• Your program should have a GUI.

7
Implementation
• Help user for public and private key selection
– Get 2 prime numbers (p and q) from user
– Check whether they are prime or not
– Calculate n and z (n should be grater than 127)
– Get e from user ( e<n, and e and z are relatively
prime)
– Choose d automatically such that ed mod z = 1
– Write public key as {e, n}
– Write private key as {d, n}
8
Implementation
• Encrypt the given text
– Get public key as {e, n} from user
– Get text string from user
– Encrypt each character by using ASCII code
of each character (convert to a number)
– Write the encrypted text in HEX encoding (4
characters output for each input- put 0 if it is
less than 4 chars).For example:
– Dec: 326 => Hex: 146 => on screen: 0146
9
Implementation
• Decrypt the given text
– Get private key as {d, n} from user
– Get encrypted text string from user as HEX
stream
– Decrypt each character by using ASCII code
of each character (convert to a number)
– Write the plaintext

10
Due date
• Due date: March 26, 2020

• You will present your implementation as a


demo in the lab as group.

• Cross validation will be done among


groups.

11
Hints

e • c = 1;
c = m mod n for (i=0;i< e;i++)
c=c*m%n;
c = c%n;

12
Hints
• To convert a decimal to Hex in c:
value.ToString("X4");

13
Screenshot of an example
program

14
Screenshot of an example
program

15
Screenshot of an example
program

16

Das könnte Ihnen auch gefallen