RSA (Rivest, Shamir and Adleman) is a cryptosystem based on factorization of big prime numbers. It is a nice and interesting application of modular arithmetic. It involves the Euler's totient function and generates a pair of key, a public one and a private one.
There are two main applications:
- Signature: Sign the message with the private key and then everybody can verify the signature with the public key.
- Encryption: Encrypt with the public key and decrypt with the private key.
- Easy: You can generate public/private keys, encrypt and decrypt in a few commands.
- Secure: The RSA algorithm is fully implemented avoiding security holes.
- Clear: The code is clear and easily readable, you can learn from it and make it totally yours.
from rsa import Rsa
rsa = new Rsa()
rsa.encrypt("public.key", "message.txt", "cypher.nop")
rsa.decrypt("private.key", "cypher.nop", "message.back")
import filecmp
assert(filecmp.cmp("message.txt", "message.back"))
This example encrypts and decrypt a message.
The library is a Python module and can be imported directly in your code.
PyRsa is made under the terms of the MIT license.