When I decrypt the 5 levels RSA encrypted message the result isn't the original message although I use the right private keys and the right private keys
I have already tried playing with the integers and the amount of encryptions. It's working if I only encrypt once
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
import ast
publickeys = []
privatekeys = []
for i in range (0,5):
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
privatekeys.append(key)
publickeys.append(key.publickey())
data = "ack"
for publickey in publickeys:
data = publickey.encrypt(str(data), 32)
for i in range (1,len(privatekeys)+1):
data = privatekeys[-i].decrypt(ast.literal_eval(str(tuple(data))))
There are no error messages but the results aren't what I expected. instead of getting the right message "ack" I am getting a weird string.