浪子归家|密码学学习笔记之Coppersmith’s Method (三)


浪子归家|密码学学习笔记之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. = PolynomialRing(ZmodN)f = (m + x)^e - cepsilon = 1 / 7# 根据公式计算参数d、h、Xd = f.degree()h = ceil(1 / (d * epsilon)) X = ceil(N**((1/d) - epsilon))roots = (coppersmith(f, N, d, h, X))[0]for root in roots:if (m + root)^e %N== c %N :print(m + root)构造的格的样式
浪子归家|密码学学习笔记之Coppersmith’s Method (三)与example3 构造的格是类似的
浪子归家|密码学学习笔记之Coppersmith’s Method (三)但其实sage已经集成了coppersmith的求根方法 , 因此简单调用一下函数就可以解决这个问题 。 这里之所以这样做其实是想映照前文 , 展示一下利用coppersmith来解决此类问题的整个过程 。
利用现成方法版exp


推荐阅读