This project implements the RSA (Rivest–Shamir–Adleman) algorithm, a popular asymmetric encryption and decryption method, using Python. RSA is widely used for secure data transmission in modern computing. The implementation allows users to encrypt and decrypt text using RSA, providing insights into the algorithm's mechanics.
- RSA algorithm for encryption and decryption
- Reading plaintext from a file or input
- Prime number validation for keys
- ASCII conversion for text encryption and decryption
- Python 3.x
sympy
library for prime number validation
- Clone the repository:
git clone https://github.com/AbdelrahmanBayoumi/RSA-Algorithm-in-Cryptography.git
- Install the required Python library:
pip install sympy
To use this program:
- Run
main.py
. - Input two prime numbers (p and q) when prompted.
- Choose to read from a file (
f
) or input plaintext (m
). - The program will display the encrypted and decrypted message.
Enter p: 17
Enter q: 19
Enter:-
- 'f' to read from file => msg.txt.
- 'm' to enter plaintext message.
f
RSA algorithm involves the following steps:
- Select two large prime numbers
p
andq
. Calculaten = p * q
andt = (p - 1) * (q - 1)
. - Choose an encryption key
e
such that1 < e < t
andgcd(e, t) == 1
. - Determine the decryption key
d
satisfyingd * e = 1 (mod t)
. - For encryption, convert plaintext to ASCII and compute
C = (P ^ e) % n
. - For decryption, convert cipher text back using
P = (C ^ d) % n
.
Contributions to this project are welcome. Please follow standard GitHub contribution guidelines.
Developed by Abdelrahman Bayoumi - GitHub. Course project for Algorithm Analysis and Design CS305, Faculty of Science, Alexandria University.