主页 > 其他  > 

RSA小总结(就目前所学)(一)

RSA小总结(就目前所学)(一)

(ps:开学好几天了。。。是时候拾起知识了)

1.共模攻击

(同一个n,不同的e,但是e1,e2互质)

关键代码:

s,s1,s2=gmpy2.gcdext(e1,e2)

m=(pow(c1,s1,n)*pow(c2,s2,n)%n)

print(libum.n2s(int(m)))

2.Rabin算法

(e=2)

关键代码: inv_p = gmpy2.invert(p, q) inv_q = gmpy2.invert(q, p) mp = pow(c, (p + 1) // 4, p) mq = pow(c, (q + 1) // 4, q) a = (inv_p * p * mq + inv_q * q * mp) % n b = n - int(a) c = (inv_p * p * mq - inv_q * q * mp) % n d = n - int(c) # 因为rabin 加密有四种结果,全部列出。 aa = [a, b, c, d] for i in aa: print(i) print(libnum.n2s(int(i))) 3.共享素数

(n1,n2有公因数)

关键代码:

p=gmpy2.gcd(n1,n2)

q1=n1//p

q2=n2//p

4.低指数加密攻击

(e很小,n很大)

关键代码:

m=iroot(c,e)

5.winner攻击(低解密指数攻击)

(e过大或者e过小)

关键代码:(脚本)

from Cryptodome.Util.number import * from gmpy2 import * from RSAwienerHacker import * import libnum

n= 639662333905190724963174274393118134850652056724765488685973275138948202602626008285649108873241886836533441901790252560580886492518792249844707754890068885294414947775869189660933854702732140888525369256213185908742658834741758334492843871934294115437721034834635565406377520933839418094457376057043593848401 e= 548564175098067125961375319851171259385596271876637657761522885808657855394647972481844447376596437557651275057610120865395646169671221375251081541213042646978655686531005856899936162320404991331623237305862913250487293880446994470841390688087392282045130633013139311548859962245908782253213294049851175315059 c= 266367266471585923035346980467315672043839080179258966276144775106482166900911004389808367589961536843898187180012055918063504477273067284037318171833017082239907978935274619109926579983150571298634653886980563681026116724117473808890951091279814434050754571460308728024448607359710055618866766919226511213734

d=hack_RSA(e,n) flag=long_to_bytes(pow(c,d,n)) print(flag)

未完待续。  

标签:

RSA小总结(就目前所学)(一)由讯客互联其他栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“RSA小总结(就目前所学)(一)