rsa - RSA中素数和消息的大小
问题描述
我正在玩玩具 RSA 源代码。我观察到,如果大小消息改变,则保持素数 p 和 q 的大小固定,然后解密的文本会改变。如果消息的大小增加到超过某些值,那么解密后我将无法获得原始明文。所以请建议对 p ,q 和消息大小的值有什么限制。意味着给定 ap 和 q 我应该选择特定大小的明文吗?示例源代码如下
# Write Python3 code here
from decimal import Decimal
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
p = int(input('Enter the value of p = '))
q = int(input('Enter the value of q = '))
no = int(input('Enter the value of text = '))
n = p * q
t = (p - 1) * (q - 1)
for e in range(2, t):
if gcd(e, t) == 1:
break
for i in range(1, 10):
x = 1 + i * t
if x % e == 0:
d = int(x / e)
break
print('pvt key= ', d)
ct = pow(no,e,n)
dt = pow(ct,d,n)
print('n = ' + str(n) + ' e = ' + str(e) + ' t = ' + str(t) + ' d = ' + str(d) + ' cipher text = ' + str(ct) + ' decrypted text = ' + str(dt))
解决方案
推荐阅读
- php - 在PHP中的同一页面上根据需要调用一次或每次函数?
- amazon-mws - 通过 MWS API 丢失/接收不正确的结算报告
- unity3d - 使用动画师运行微调器的平滑连续旋转动画
- css - 如何在 Sass 中将 VW 转换为 px?
- r-markdown - 在 xaringan 中突出显示代码选择
- android - 将 AdColony 与中介集成时无法第二次加载广告
- javascript - 使用 Javascript 在页面加载时禁用 cookie
- javascript - 我应该如何将json响应对象与for循环的变量J连接起来
- python - 将光标位置设置为 TextInput
- dart - 类之外的小部件的“状态”是什么