Python RSA加密数字不起作用,为什么?

Python RSA加密数字不起作用,为什么?,python,rsa,Python,Rsa,我正在为一个做简单RSA加密和解密的类编写一个程序。程序运行一个实例时生成的数字如下: encryption: p = 37 q = 11 n = 407 phi = 360 e = 17 d = 24 Enter the message you wish to encrypt: hello ASCII: 104 ASCII: 101 ASCII: 108 ASCII: 108 ASCII: 111 Here is your encrypted message: :Žřřo decryption

我正在为一个做简单RSA加密和解密的类编写一个程序。程序运行一个实例时生成的数字如下:

encryption:
p = 37
q = 11
n = 407
phi = 360
e = 17
d = 24
Enter the message you wish to encrypt: hello
ASCII: 104
ASCII: 101
ASCII: 108
ASCII: 108
ASCII: 111
Here is your encrypted message:
:Žřřo
decryption:
Enter in a value for n:407
Enter in a value for d:24
Enter the message you wish to decrypt::Žřřo
ASCII: 158
ASCII: 223
ASCII: 47
ASCII: 47
ASCII: 111
Here is your decrypted message:
ß//o
我的问题是,为什么解密后不返回正确的ASCII值?满足RSA的所有规则:
1.p和q是独立的素数
2.e和phi是互质
3.d是e的模乘逆,使得e*d模n=1


该程序随机生成p、q和e,并在每次运行时计算n、phi和d。其他的例子也类似,所有的RSA规则都满足了,但仍然没有得到正确的解密。

也许这只是你问题中的一个输入错误,但我认为
d
应该是
e
phi(n)
,而不是
n

先生,你刚刚正式保存了我的分数。根据我的教授告诉我们应该是e*d mod n是正确的,我已经在这个项目上工作了20多个小时。但你是对的。非常感谢。