浪子归家|密码学学习笔记之Coppersmith’s Method (三)
单元coppersmith’s method 学习最终章 , 详解 第三届强网杯 之copper study , 【这一波 , 这一波是首尾呼应 。 】
第一关:Stereotyped messages已知n,e=3,c , m共512bit但是低72bit未知 , 原理可参考Mathematics of Public Key Cryptography ch19 。 也即前文所述 。
[+]Generating challenge 1[+]n=0x44e360ce873d18d33eecc0829eb0801e71950e26576963c470f91f4c5e7f3e951f65404c6a87f4328495c9c64d39271f3317081aeab34bdf350c5f9bf0c5a49668f763cbf404e66f210336042c6a6e43eed6c6eaca69287ed91b2841148668fd3881b241317574cc8b307fb41593ff7caaa6f09e32f657399c63fe5f68995c5dL[+]e=3[+]m=random.getrandbits(512)[+]c=pow(m,e,n)=0x20d40eecc8108d6c57b0ea2e1d7d165fb342813764f3760baf71e7929e3c22476de15b5e665ff8b869b5ed3a672aad4e9ef330bb7e18329ce2d0cccae369e244002882a273d3bf5a13b8936974768a920f5cbee52d0bb0323f867ff6305c5aa7ceb99453172332cd9837fdb05d6ea2d7eac39fd0d39960dc9ddbdd40f82b444bL[+]((m>>72)<<72)=0x5377a12cada023e2714b4a9e80f1da87ca567f084e2862e704b813cd7f69b8dbbf67d60e73610fabb7896eeb3cc5a2c0915d03f9f8d44d000000000000000000L[-]long_to_bytes(m).encode('hex')=
这道题我们完全可以将题面转化为在求方程f(x) = (m+x)^3 在模N下的解
所以可以直接套我们前面所描述的方法
exp:
# 展示格的样式def matrix_overview(B, bound):for ii in range(B.dimensions()[0]):a = ('%02d ' % ii)for jj in range(B.dimensions()[1]):a += '0' if B[ii,jj] == 0 else 'X'a += ' 'if B[ii, ii] >= bound:a += '~'print (a)def coppersmith(pol, modulus, h, X):# 计算矩阵维度n = d * h# 将多项式转到整数环上polZ = pol.change_ring(ZZ)x = polZ.parent().gen()# 构造上文所述lattice , polZ(x * X) 就是环上的多项式f(X * x) , 所以这里与上文不同的点就在于引入了变量x , 但变量x在后面的矩阵构造中会被抹掉 。g = []for i in range(h):for j in range(d):g.append((x * X)**j * modulus**(h - 1 - i) * polZ(x * X)**i)B = Matrix(ZZ, n)for i in range(n):for j in range(i+1):B[i, j] = g[i][j]# 展示格的样式matrix_overview(B,modulus^h)# LLL算法B = B.LLL()# 将最短向量转化为多项式 , 并且去除相应的Xnew_pol = 0for i in range(n):new_pol += x**i * B[0, i] / X**i# 解方程potential_roots = new_pol.roots()return potential_rootsN =e =c =m =ZmodN = Zmod(N)P.
构造的格的样式
与example3 构造的格是类似的
但其实sage已经集成了coppersmith的求根方法 , 因此简单调用一下函数就可以解决这个问题 。 这里之所以这样做其实是想映照前文 , 展示一下利用coppersmith来解决此类问题的整个过程 。
利用现成方法版exp
推荐阅读
- 爆笑社|要不然不会这么潇洒!,搞笑gif-大哥以前一定做过浪子
- 晚安sky浪子|铁轨旁摆摊售卖,火车直接从人群中穿过!,世界最“危险”菜市场
- 浪子归家|小米新型“武器”出世!格力美的都得靠边站,雷军这步又走对了
- 浪子归家|美国瞄准中芯国际?华为余承东:这是教训,台积电之后
- 浪子归家|日本"妻子"机器人遭疯抢,10万一个,和真人一模一样?
- 浪子归家|台积电之后,美国瞄准中芯国际?华为余承东:这是教训
- 浪子归家|余承东的鸿蒙系统突破谷歌安卓限制
- 浪子归家|风格迥然不同的荣耀20i手机壳,看看哪款适合你
- 浪子归家|倒计时4天丨凭什么必须要逛科明展厅?科明说:凭的就是实力
- 科技浪子|甚至可变透明探索版,手机后盖迎来大变革!这款手机后盖可变色