[英]How can i take the remain of a modulo in python?
我試圖對公鑰和私鑰算法做一個簡單的解釋。 加密部分工作正常,但解密部分有點不對。 我只想要模數(2^7,33)的剩余部分 29。 這是我到目前為止:
p= 3
q= 11
n = p*q
z = (p-1)*(q-1)
e = 7
d = (z + 1)/e
a= divmod(d*e,z)
PublicKey = (e,n)
PrivateKey = (d,n)
#Encrypt
message = 2
c = divmod(2**e,n)
print c
#Decrypt
decryption = divmod((c**2),n)
print decryption
錯誤是:
Traceback (most recent call last):
File "C:/Python27/rsa2.py", line 17, in <module>
decryption = divmod((c**2),n)
TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'
你的問題在最后,在這一行:
decryption = divmod((c**2),n)
刪除 c 變量周圍的 ()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.