我正在尝试使用公钥和私钥进行编码。但是,当我尝试加密时,我一直收到错误。这就是我到目前为止所做的:
import random
Primes = [2,3,5,7,9,11,13,15]
p = random.choice(Primes)
q = random.choice(Primes)
n = p*q
z = (p-1)*(q-1)
deck = list(range(1,z))
e = random.choice(deck)
d = (z + 1)/e
a= divmod(d*e,z)
PublicKey = (e,n)
PrivateKey = (d,n)
input = raw_input ('Write text: ')
input = input.lower()
message = []
for character in input:
number = ord(character)
message.append(number)
#Encrypt
for character in message:
c = message**e % n
#Decrypt
for character in c:
decryption = c**d % n
程序运行正常,直到我通过加密部分。我得到的错误是:
Traceback (most recent call last):
File "C:/Python27/rsa2.py", line 30, in <module>
c = message**e % n
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'