diff --git a/src/py-cli/encrypt_decrypt.py b/src/py-cli/encrypt_decrypt.py new file mode 100755 index 0000000..e02d4e0 --- /dev/null +++ b/src/py-cli/encrypt_decrypt.py @@ -0,0 +1,29 @@ +""" +Encrypting and decrypting a message + +@author Todorov-Lachezar +""" + +import rsa + +# Generates public and private keys +# Method takes in key length as a parameter +# Note: the key length should be >16 +publicKey, privateKey = rsa.newkeys(512) + +# the message we want to encrypt +message = "Hello World" + +# Encrypts the message with the public key +# Note: make sure to encode the message before encrypting +encMessage = rsa.encrypt(message.encode(), + publicKey) + +print("original string: ", message) +print("encrypted string: ", encMessage) + +# Decrypts the encrypted message with the private key +# Note: make sure to decode the message after decryption +decMessage = rsa.decrypt(encMessage, privateKey).decode() + +print("decrypted string: ", decMessage) \ No newline at end of file