题目:
from Crypto.Util.number import *
flag = open('flag.txt').read()
nbit = 64
while True:
p, q = getPrime(nbit), getPrime(nbit)
PP = int(str(p) + str(p) + str(q) + str(q))
QQ = int(str(q) + str(q) + str(p) + str(p))
if isPrime(PP) and isPrime(QQ):
break
n = PP * QQ
m = bytes_to_long(flag.encode())
c = pow(m, 65537, n)
print('n =', n)
print('c =', c)
n = 177269125756508652546242326065138402971542751112423326033880862868822164234452280738170245589798474033047460920552550018968571267978283756742722231922451193
c = 47718022601324543399078395957095083753201631332808949406927091589044837556469300807728484035581447960954603540348152501053100067139486887367207461593404096
题目给了我们两个文件,分别是task(题目中数据的来源)和output(数据大小),首先,审计题目:
我们可以知道p和q都是64比特的数值,转化为10进制大概为(10^19--10^20)之间,所以我们可以将pp和qq用十进制的加减来进行表示:
pp = 10^60*p + 10^40*p + 10^20*q + q 或者 10^57*p + 10^38*p + 10^19*q + q
qq同上类似,然后我们将两个数相乘,可以求得n = pp*qq的最高位一定为 10^120*pq ,而其他的数值都一定小于这个值,所以我们可以将n // 10^120+...来求得pq的值;
print(n//(pow(10,120)+2*pow(10,100)+pow(10,80)))
print(n//(pow(10,114)+2*pow(10,95)+pow(10,76)))
print(n//(pow(10,117)+pow(10,97)+pow(10,98)+pow(10,78)))
177269125756508652542696943550008229
177269125756508652510788500913836672467612
177269125756508652526742722231922451193
求得我们所需的值后,我们将上面的数进行yafu分解,可适当加减1,2数值。
求得我们所需的p和q值,接下来,进行常规的rsa求解即可:
wp:
n = 177269125756508652546242326065138402971542751112423326033880862868822164234452280738170245589798474033047460920552550018968571267978283756742722231922451193
c = 47718022601324543399078395957095083753201631332808949406927091589044837556469300807728484035581447960954603540348152501053100067139486887367207461593404096
import gmpy2
from Crypto.Util.number import *
e = 65537
print(n//(pow(10,120)+2*pow(10,100)+pow(10,80)))
print(n//(pow(10,114)+2*pow(10,95)+pow(10,76)))
print(n//(pow(10,117)+pow(10,97)+pow(10,98)+pow(10,78)))
p = '9788542938580474429'
q = '18109858317913867117'
pp = int( p+p+q+q )
qq = int( q+q+p+p )
n = pp*qq
phi = ( pp-1 )*( qq-1 )
d = gmpy2.invert ( e,phi )
print ( long_to_bytes ( gmpy2.powmod ( c,d,n ) ) )