python - 从背包密码中的公钥计算私钥
问题描述
我为Merkle-Hellman 背包密码系统编写了一个 python 程序 目标是给定一个公钥 我必须找到一个有效的陷门秘密 这样得到的私钥是一个超级递增的私钥。还给出了vInverse/u ~ 0.3463790532。
所以我试图通过选择 vInverse 来找到一个有效的陷门秘密,以便它大约等于这个数字。
但不幸的是,程序永远不会终止。可能我需要巧妙地改变 vInverse 或者我做错了什么。
A = [6517080, 1056695235, 1220060160, 26032114, 3005098, 12816924, 1019797155, 103947426,
735394924, 1280688572, 830674258, 367353505, 687914, 640579625, 1072069574,
1262094708, 631083560, 157426933, 1918918, 207931058, 315759016, 415500056,
609903359, 536252023, 51883198, 936198737]
u = max(A)+1
# S = A * v^-1 mod u
found = False
def mod_function(a):
return (a*vInverseJ2) % u_mod_element
def checkSuperIncreasing(S):
S.sort()
for index, element in enumerate(S):
if(element <= sum(S[0:index])):
return False
return True
for i in range(u, 10*u, 1):
vInverse = int(0.3463790532 * i)
for vInverseJ in range(vInverse-100, vInverse+100+1):
global vInverseJ2
vInverseJ2 = vInverseJ
global u_mod_element
u_mod_element = i
S = list(map(mod_function, A))
if(checkSuperIncreasing(S)):
print("u = ", u_mod_element, " , vInverse = ", vInverse)
found = True
break
if found:
break
# The set S may not be in a sorted order
解决方案
推荐阅读
- vba - 为代码创建的控件创建鼠标事件
- reactjs - Webpack - TypeError:$ 不是函数
- java - 为什么 O(n) 时间复杂度的 leetcode 提交比 O(n log n) 时间复杂度的运行时间更长?
- php - Vimeo API PHP 调用
- powershell - 比较来自不同目录的文件夹名称并将两个结果输出到 csv - PowerShell
- c++ - 如何使用 Arduino 去抖动位掩码读数?(不是按钮...)
- gnuplot - 使用范围时,stats 命令不返回预期值
- c# - 删除第一个事件之后的所有事件,直到第一个事件被处理
- python - 如何为这个 Jar 和 candy python 问题创建解决方案?
- php - Stripe Webhook 错误:警告:array_keys() 期望参数 1 是数组,给定字符串