Write a Java program to implement RSA Algoithm | RSA Algorithm in Java | Cryptography
HARDWARE
AND SOFTWARE REQUIREMENT:
1. Intel based Desktop PC: - RAM of 512 MB
2. Notepad/Notepad ++ editor
and Command Prompt or
3. IntelliJ IDEA Community Edition/ Eclipse
THEORY:
Ø
RSA is
an encryption algorithm, in order to have secure transmission of messages over the internet.
Ø Many protocols like Secure Shell, S/MIME, and SSL/TLS are based on RSA
for encryption and digital signature functions.
Ø It is an asymmetric encryption technique [Asymmetric
means that there are two different keys i.e. Public key and Private key. That’s
why it is also known as public key cryptography].
Ø
The public key is used to encrypt
messages and can be known to everyone; Messages encrypted using the public key
can only be decrypted with the private key / Secret key.
An example of
asymmetric cryptography in Client-Server Communication:
1.
A client (web browser) sends its shared
key to the web server and requests for
some data.
2.
The server encrypts the data using
client’s shared key and sends the encrypted data.
3.
Client receives this data and
decrypts it with the help of secret key.
Encrypting message:
Ø The encryption with the help of
public key e is done by using following
formula
c = me
mod n
Decrypting message
Ø The decryption of ciphertext with the
help of private key d in the following procedure:
m = cd
mod n
SOURCE
CODE:
import java.math.*;
import java.util.Random;
import java.util.Scanner;
public class RSA {
static Scanner sc = new Scanner(System.in);
public static void main(String[ ]args) {
System.out.print("Enter a Prime number: ");
BigInteger p=sc.nextBigInteger(); //Here's one prime number..
System.out.print("Enter another prime number: ");
BigInteger q=sc.nextBigInteger(); //..and another.
BigInteger n=p.multiply(q);
BigInteger n2=p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
BigInteger e = generateE(n2);
BigInteger d = e.modInverse(n2); // Here's the multiplicative inverse
System.out.println("Encryption keys are: " + e + ", " + n);
System.out.println("Decryption keys are: " + d + ", " + n);
}
private static BigInteger generateE(BigInteger fiofn){
int y, intGCD;
Random x = new Random();
BigInteger e;
do{
y= x.nextInt(fiofn.intValue()-1);
String z = Integer.toString(y);
e = new BigInteger(z);
BigInteger gcd = fiofn.gcd(e);
intGCD = gcd.intValue();
}
while(y<=2 || intGCD!=1);
return e;
}
}
OUTPUT:
I found your blog on google and I just added you to my Google News Reader. Keep up the great work
ReplyDeleteDigital Marketing Courses in Bangalore
Digital Marketing Training in Bangalore
AWS Training in Bangalore
Devops Training in Bangalore
Python Training in Bangalore
AWS Course in Bangalore
Best Devops Training in Bangalore
Python Course in Bangalore
Seo Training in Bangalore
Parents seeking quality early education often look for schools that offer a balanced blend of academic learning and creative development. At this foundational stage, a nurturing environment with experienced educators plays a crucial role in shaping young minds. The right school helps children build confidence, curiosity, and essential life skills.
ReplyDeleteLKG Admission in Pondicherry is a significant step for families wanting to ensure a strong start for their child’s education journey. Schools that focus on holistic development, engaging curriculum, and individualized attention are highly preferred. With a supportive and stimulating atmosphere, these institutions lay the groundwork for lifelong learning and growth.
Choosing the right school lays the foundation for a child’s academic and personal growth. A well-structured curriculum, experienced faculty, and holistic development opportunities are essential factors parents consider when selecting an educational institution. Schools affiliated with a recognized national board offer consistency and credibility in education standards.
ReplyDeleteFor parents seeking quality education, CBSE School Admission in Pondicherry presents an ideal opportunity. These schools follow a comprehensive curriculum that emphasizes both scholastic and co-scholastic development. With a focus on nurturing individual potential and preparing students for future challenges, they ensure a balanced learning environment that supports intellectual, emotional, and social growth.