<filename>rsadecrypt.py
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
import ast

random_generator = Random.new().read
key = RSA.generate(1024, random_generator) #generate pub and priv key

publickey = key.publickey() # pub key export for exchange




filehandle = "values.txt"

filelist = []
with open(filehandle) as f:
    lines = f.readlines()
    filelist = [line.replace("\n", "") for line in lines]
    f.close()

print(filelist)

cryptodict= {}

for item in filelist[1:]:
    print(item)
    pair = tuple(item[1:-1])
    cryptodict[str(pair[0])] = int(pair[1])

print(cryptodict)

    	


random_generator = Random.new().read
key = RSA.generate(1024, random_generator) #generate pub and priv key

publickey = key.publickey() # pub key export for exchange

encrypted = publickey.encrypt('encrypt this message', 32)
#message to encrypt is in the above line 'encrypt this message'

print('encrypted message:', encrypted) #ciphertext
f = open ('encryption.txt', 'w')
f.write(str(encrypted)) #write ciphertext to file
f.close()

#decrypted code below

f = open('encryption.txt', 'r')
message = f.read()


decrypted = key.decrypt(ast.literal_eval(str(encrypted)))

print('decrypted', decrypted)

f = open ('encryption.txt', 'w')
f.write(str(message))
f.write(str(decrypted))
f.close()

<filename>rsadecrypt.py
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
import ast

random_generator = Random.new().read
key = RSA.generate(1024, random_generator) #generate pub and priv key

publickey = key.publickey() # pub key export for exchange




filehandle = "values.txt"

filelist = []
with open(filehandle) as f:
    lines = f.readlines()
    filelist = [line.replace("\n", "") for line in lines]
    f.close()

print(filelist)

cryptodict= {}

for item in filelist[1:]:
    print(item)
    pair = tuple(item[1:-1])
    cryptodict[str(pair[0])] = int(pair[1])

print(cryptodict)

    	


random_generator = Random.new().read
key = RSA.generate(1024, random_generator) #generate pub and priv key

publickey = key.publickey() # pub key export for exchange

encrypted = publickey.encrypt('encrypt this message', 32)
#message to encrypt is in the above line 'encrypt this message'

print('encrypted message:', encrypted) #ciphertext
f = open ('encryption.txt', 'w')
f.write(str(encrypted)) #write ciphertext to file
f.close()

#decrypted code below

f = open('encryption.txt', 'r')
message = f.read()


decrypted = key.decrypt(ast.literal_eval(str(encrypted)))

print('decrypted', decrypted)

f = open ('encryption.txt', 'w')
f.write(str(message))
f.write(str(decrypted))
f.close()

#generate pub and priv key # pub key export for exchange #generate pub and priv key # pub key export for exchange #message to encrypt is in the above line 'encrypt this message' #ciphertext #write ciphertext to file #decrypted code below