[SWPU 2020]happy
题目附件:
('c=', '0x7a7e031f14f6b6c3292d11a41161d2491ce8bcdc67ef1baa9eL')
('e=', '0x872a335')
#q + q*p^3 =1285367317452089980789441829580397855321901891350429414413655782431779727560841427444135440068248152908241981758331600586
#qp + q *p^2 = 1109691832903289208389283296592510864729403914873734836011311325874120780079555500202475594
解题:
根据附件可知需要求出p,q,一看就是需要求公约数的,用到的原理
hint1 = q + qp^3 = (1+p^3)q = q(1+p)(p^2-p+1)
hint2 = qp + qp^2 = q(1+p)p
gcd(hint1,hint2) = q(1+p)
p = hint2 / q(1+p)
q = gift // (p+1)
得到p,q后根据欧拉定理,解题代码如下:
from Crypto.Util.number import *
from gmpy2 import *
c=0x7a7e031f14f6b6c3292d11a41161d2491ce8bcdc67ef1baa9e
e=0x872a335
#q + q*p^3 =1285367317452089980789441829580397855321901891350429414413655782431779727560841427444135440068248152908241981758331600586
#qp + q *p^2 = 1109691832903289208389283296592510864729403914873734836011311325874120780079555500202475594
hint1 = 1285367317452089980789441829580397855321901891350429414413655782431779727560841427444135440068248152908241981758331600586
hint2 = 1109691832903289208389283296592510864729403914873734836011311325874120780079555500202475594
gift = gcd(hint1,hint2)
p = hint2//gift
q = gift // (p+1)
n= p*q
phi = (p-1)*(q-1)
d = invert(e, phi)
flag = pow(c, d, n)
print(long_to_bytes(flag))
flag{happy_rsa_1}