Skip to content

abdo-essam/RSA-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RSA-algorithm

RSA encryption and decryption

Faculty Of Computer And Artificial Intelligence Cairo University FCAI-CU

Cyber Security Assignment

This Java program implements the RSA encryption and decryption algorithm using the Square and Multiply algorithm for modular exponentiation and the Chinese Remainder Theorem for decryption. The program takes a plain text message as input and encrypts it using a public key generated by the program. The encrypted message is then decrypted using the corresponding private key generated by the program.

The program generates two large prime numbers p and q, and computes their product n=pq, which serves as the modulus for the RSA algorithm. The program also computes Euler's totient function phi(n) = (p-1)(q-1), which is used to find the public and private keys.

The program then prompts the user to enter a plain text message, which is converted to a byte array of ASCII values. Each byte in the array is then encrypted using the public key and the Square and Multiply algorithm, and the resulting encrypted values are stored in an array list.

The program then decrypts each encrypted byte using the private key and the Chinese Remainder Theorem, and the resulting decrypted values are stored in another array list. The decrypted byte values are then converted back to characters and printed as the decrypted message.

Overall, this program provides a basic implementation of the RSA encryption and decryption algorithm in Java, using some common techniques for modular exponentiation and decryption. However, it should be noted that this implementation may not be secure enough for real-world applications, as it uses fixed prime numbers and does not include any additional security measures such as padding or randomization.

afdf