You are on page 1of 10

RSA algorithm (Rivest-Shamir-Adleman):

Program Discussion:

First of all, we write the algorithm steps and manually encrypt and decrypt by letting small values for p
and q.
Code Discussion:

Step 1:

selecting two primes p and q.

Step 2:

 Calculating n=p×q

Step 3:

Calculating totient ϕ(n)=(p−1)x(q−1)

Step 4:

Now calculate public key, e AND Private Key, d :

Step 5:

Encryption:

Step 6:

Decryption:

Step 7:

Print Public and Private key components


Design Issues:

 Public Key Generation: (must be co-prime).

To find a public key "e", I used a "while" loop to test different possible "e" until
(m.gcd(e)).equals(BigInteger.ONE).

 We are not able to input P and Q from user as it’s a BigInteger value which is a RANDOM
NUMBER.
 When calling probablePrime(), it requires a random number generator. I used a
java.util,Random constructor to created a random number generator. Another option is to use a
java.security.SecureRandom contrustor.
 BitLength 64 bit to 512 bit

Testing:

Output:

o Test by entering different plaintexts:

o In testing phase We have changed the bit size to 64, the code isn’t decrypted back.
o We tried to input the values of P and Q but that didn’t work.
Elgamal Algorithm:
The algorithm and program discussion

First of all, we write the algorithm steps and manually encrypt and decrypt by letting small values for p.

So basically the key generation part of Elgamal cryptography consists of selecting a prime number,

Selecting a decryption key. Since the public key has 3 parts, the first part E1 is chosen, then the second
one the E2. Which is calculated as E2 = E1^D mod P. So finally our public key has been generated i.e
(E1,E2,P). And in the same step we have our private key chosen.

Later Encryption and decryption can be done. Encryption process, generates a random integer R. First
part of the ciphertext is generated C1= E1^R mod P. Then second part of the ciphertext is generated
using the plaintext C2 = (PT*E2^R) mod P. So now the ciphertext is CT = (C1,C2)

Code Discussion

Elgamal Key Generation


Elgamal Encryption

Elgamal Decryption
Design Issues:

1. Message must be in the form of an integer

2. Since we are using biginteger, allocating a value is not possible for p and the other variables, it gives
an error.

3. That’s exactly why I have provided static secret key and decryption key in the program. The user
might not be able to exactly provide 1024bits. So that’s a design issue.

Testing

Testing for bad number. If plaintext is -1(a bad number then the result is bad)

Big numbers are encoded and decoded with ease


Prime number is 1024 bit as suggested in the question.

Libraries:

I made a class called tools.java. In order to separate the process of input from the main code

Java.math library for complex math performance such as mod and inverse mod.

Biginteger.java for big integer handling and processing also probable prime function is a part of big
integer.

You might also like