The first script (generate_keys.pl) creates the public and the private key. It takes two prime numbers as arguments, in this context commonly referred to as p
and n
:
Now, I can encrypt a message with the second script (encrypt_decrypt.pl) and the public key: the first two parameters are the public key, the third parameter the message to be encrypted.
The message I want to encrypt is the number 42
:
In order to decrypt 166097
, I use encrypt_decrypt.pl again, this time with the private key:
Links
RSA key generation example with python was a very helpful page for me.Modular multiplicative inverse on wikipedia.
Extended euclidean algorithm on wikipedia.
RSA (cryptosystem) on wikipedia.