CN-5 KN
CN-5 KN
DESCRIPTION:
RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is
an asymmetric cryptographic algorithm. Asymmetric means that there are two different
keys. This is also called public key cryptography, because one of them can be given to
everyone.
A basic principle behind RSA is the observation that it is practical to find three very
large positive integers e, d and n such that with modular exponentiation for all integer
m: (m^e ) d = m (mod n)
The public key is represented by the integers n and e; and, the private key, by the
integer d. m represents the message. RSA involves a public key and a private key. The
public key can be known by everyone and is used for encrypting messages. The
intention is that messages encrypted with the public key can only be decrypted in a
reasonable amount of time using the private key.
ALGORITHM:
STEP-1: Select two co-prime numbers as p andq.
STEP-2: Compute n as the product of p and q.
STEP-3: Compute (p-1)*(q-1) and store it in z.
STEP-4: Select a random prime number e that is less than that of z. STEP-5: Compute
the private key, d as e * mod-1(z).
STEP-6: The cipher text is computed as message e * mod n.
STEP-7: Decryption is done as cipher d mod n.
SOURCE CODE:
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Scanner;
e = BigInteger.valueOf(2);
while (e.compareTo(phi) < 0) {
if (e.gcd(phi).equals(BigInteger.ONE)) {
break;
}
e = e.add(BigInteger.ONE);
}
URK22CS7106
d = e.modInverse(phi);
}
RESULT:
The program generates RSA keys, encrypts a user-input message, and decrypts it back. It
verifies successful encryption and decryption by comparing the original and decrypted
messages.