首页 > 其他 > 详细

Discrete Log Algorithms :Baby-step giant-step 【二】

时间:2018-12-21 00:43:42      阅读:182      评论:0      收藏:0      [点我收藏+]

技术分享图片技术分享图片技术分享图片技术分享图片

 

 

 

import gmpy2
def discreteLog(g,p,a):              #离散对数,求 g^x=a mod p中的x
    table={}
    sq=gmpy2.isqrt(p-1)
    m=gmpy2.add(sq,1)       #向上取整
    for i in range(m):
        k=-i*m
        y=gmpy2.powmod(g,k,p)
        mod=((a%p)*y)%p
        table.update({mod:i})
    j=0
    while True:
        result=gmpy2.powmod(g,j,p)
        if result in table.keys():
            sa=m*table[result]+j
            return sa
            #return table[result],m      #将对应的下标返回
        else:
            j=j+1
        
        
p=93450983094850938450983409623
a=45416776270485369791375944998 

x=discreteLog(-2,p,a)
print(x)        

 

小的可以,大的数就报错“Memory error”了

 

Discrete Log Algorithms :Baby-step giant-step 【二】

原文:https://www.cnblogs.com/Guhongying/p/10153395.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!