This is a simple implementation of the RSA (Rivest-Shamir-Adleman) encryption and decryption algorithm using Python.
RSA is a widely used public-key encryption algorithm. It uses a pair of keys, a public key for encryption, and a private key for decryption. The security of RSA relies on the practical difficulty of factoring the product of two large prime numbers, the factoring problem.
The implementation consists of the following main steps:
-
Key Generation: Two large prime numbers,
p
andq
, are generated. The product ofp
andq
is used as the modulusn
for both the public and private keys. The public key also includes an exponente
, while the private key includes an exponentd
. -
Encryption: A message
m
is encrypted using the public key(n, e)
to produce the ciphertextc
. The encryption function is defined asc ≡ m^e (mod n)
. -
Decryption: The ciphertext
c
is decrypted using the private key(n, d)
to recover the original messagem
. The decryption function is defined asm ≡ c^d (mod n)
.
To use this implementation, follow these steps:
-
Open a Python environment.
-
Run the
main.py
and give a custom parameter being integer file. -
You will be prompted to either generate new keys or use existing ones.
-
If you choose to generate new keys, the program will create new public and private keys.
-
Enter a message to encrypt or decrypt.
-
Follow the prompts to encrypt or decrypt the message.
main.py
: Contains the RSA implementation.README.md
: This file.
This implementation does not rely on any external libraries.
This is a basic implementation for educational purposes. In practice, RSA encryption involves additional considerations, such as padding schemes and optimizations for performance and security.
This project is licensed under the MIT License - see the LICENSE file for details.