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




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 【二】的更多相关文章
- POJ 2417 Discrete Logging ( Baby step giant step )
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3696 Accepted: 1727 ...
- 解高次同余方程 (A^x=B(mod C),0<=x<C)Baby Step Giant Step算法
先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝 扩展Baby Step Gian ...
- 数论之高次同余方程(Baby Step Giant Step + 拓展BSGS)
什么叫高次同余方程?说白了就是解决这样一个问题: A^x=B(mod C),求最小的x值. baby step giant step算法 题目条件:C是素数(事实上,A与C互质就可以.为什么?在BSG ...
- [置顶] hdu2815 扩展Baby step,Giant step入门
题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...
- HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法
联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...
- POJ 3243 Clever Y (求解高次同余方程A^x=B(mod C) Baby Step Giant Step算法)
不理解Baby Step Giant Step算法,请戳: http://www.cnblogs.com/chenxiwenruo/p/3554885.html #include <iostre ...
- 【POJ2417】baby step giant step
最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...
- 『高次同余方程 Baby Step Giant Step算法』
高次同余方程 一般来说,高次同余方程分\(a^x \equiv b(mod\ p)\)和\(x^a \equiv b(mod\ p)\)两种,其中后者的难度较大,本片博客仅将介绍第一类方程的解决方法. ...
- HDU 2815 扩展baby step giant step 算法
题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...
随机推荐
- Nginx和PHP上传文件大小的限制
Nginx client_max_body_size 80m; PHP php.ini file_uploads = on ; 是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tm ...
- 【题解】Luogu CF86D Powerful array
原题传送门 裸的莫队啊,我博客里有对莫队较详细的介绍 这道题很简单,可以说是裸的模板 但是如何在已有的值上进行操作? 小学生应该都知道 那么转移就超级简单了qaq inline void add(re ...
- amqp 抓包
1. wireshark 2. tcpick -yR -r file.name
- 20145311王亦徐 《网络对抗技术》 Web安全基础实践
2014531王亦徐 <网络对抗技术> Web安全基础实践 实验内容 利用WebGoat平台尝试了一些XSS.CSRF.SQL注入攻击 基础问题回答 1.SQL注入攻击原理,如何防御原理: ...
- VC++ 使用CreateProcess创建新进程
https://www.cnblogs.com/fancing/p/6477918.html #include <windows.h> #include <tchar.h> # ...
- "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to ma
Centos7.5 ansible第一次使用模块报错 问题: [root@m01 ~]# ansible webservers -m ping -i ./hosts 172.16.1.7 | FAIL ...
- android studio设计模式和文本模式切换
- 查看Windows系统信息
在终端输入"msinfo32". ms>Microsoft info>information
- Eclipse关联Github
摘自:http://jingyan.baidu.com/article/64d05a0262f013de55f73bcc.html 检查Eclipse中是否已安装Git插件,菜单栏Help -> ...
- SP10707 COT2 - Count on a tree II 莫队
链接 https://vjudge.net/problem/SPOJ-COT2 https://www.luogu.org/problemnew/show/SP10707 思路 dfs欧拉序转化为普通 ...