问题描述
我正在研究中间会议算法;也称为“碰撞算法”。这是代码
Python 3程序使用碰撞算法计算离散对数问题
import math;
def discreteLogarithm(a,b,m):
n = int(math.sqrt (m) + 1);
# Calculate a ^ n
an = 1;
for i in range(n):
an = (an * a) % m;
value = [0 for i in range(m)];
# Store all values of a^(n*i) of LHS
cur = an;
for i in range(1,n + 1):
if (value[ cur ] == 0):
value[ cur ] = i;
cur = (cur * an) % m;
cur = b;
for i in range(n + 1):
# Calculate (a ^ j) * b and check
# for collision
if (value[cur] > 0):
ans = value[cur] * n - i;
if (ans < m):
return ans;
cur = (cur * a) % m;
return -1;
# Driver code
a = 2;
b = 3;
m = 5;
print(discreteLogarithm(a,m));
a = 3;
b = 7;
m = 11;
print(discreteLogarithm(a,m));
# This code is contributed by mits.
我实际上在考虑这段代码的一部分时遇到了问题
1
如果可以修改下面的代码行,以使用共同的差异将总数(n-1)
分成不同的数组,直到用完原始数字(n-1)
。像这样的东西; 0 to 29 (0 to 3,4 to 7,8 to 11,12 to 15,16 to 19,20 to 23,24 to 27,28 to 29)
。重点是我的目标是将数组(0 to 29)
像示例一样分散到一定数量的数组中,直到使用公有差(4)将大数(29)用尽为止。而且,我还在考虑是否可以在对每个数组执行暴力破解后,通过操作脚本来打印出数组。这是代码;
# Store all values of a^(n*i) of LHS
cur = an;
for i in range(1,n + 1):
if (value[ cur ] == 0):
value[ cur ] = i;
cur = (cur * an) % m;
({For i in (0 to n-1)
;按数字顺序以具有公共差异P的分量划分,直到用完N-1
为止;当阵列上的蛮力完成时,计算,存储ia并打印每个阵列。差a =乘数点(2))。
编辑:而且我现在了解到,由于渐进式产生的常数,因此可以使用算术级数来解决这个问题
我很乐意为此提供一切帮助(我是菜鸟)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)