from Crypto.Util.number import long_to_bytes N = [...] C = [...] Q = [] R = [] D = [] t = 0 for _ inrange(9): M = 2^130 L = [[0for _ inrange(9)] for _ inrange(9)] L[0] = [M]+N[0:t] + N[t+1:] for i inrange(9): L[i][i] = - N[t] L[0][0] = M MQ = abs(matrix(L).LLL()[0][0]) assert MQ % M == 0 Q.append(MQ // M) t+=1
for n,q inzip(N,Q): R.append(n % q)
p = (N[0] - R[0]) // Q[0]
for i inrange(9): phi = (p-1) * (Q[i]-1) D.append(inverse_mod(0x1337,phi)) for c,d,q inzip(C,D,Q): print(long_to_bytes(pow(c,d,p*q))[-5:].decode(),end='')
print(hex(pow(bytes_to_long(b'Common prime RSA is a variant of RSA' + long_to_bytes(g1) + b'And the common factor g is large prime and p=2ga+1 q=2gb+1'), 3, n1))) # 0x27d8d7249643668ffc115be8b61775c60596e51f6313b47ad5af8493526922f5e10026a2cdaef74e22c3eec959dd8771abe3495b18d19f97623f5a3f65f22ff8fc294fc37ceb3b43ebbbf8a9bcf622922e22c5520dbd523483b9dc54fdffcd1a1b3f02ca1f53b75413fb79399ca00034f2acf108ac9a01bd24d2b9df6e27d156
from Crypto.Util.number import long_to_bytes as l2b,bytes_to_long as b2l from time import time from gmpy2 import iroot n1 = 0x48b11209b62c5bc580d00fc94886272b92814ce35fcd265b2915c6917a299bc54c2c0603c41f8bf7c8f6f2a545eb03d38f99ec995bf6658bb1a2d23056ee21c7230caa2decec688ea9ee00b0d50b39e8cd23eb2c3ddeb20f5ab26777b80052c171f47b716e72f6aee9cece92776fc65119046f9a1ad92c40e2094d7ed7526d49 n2 = 0x6d457110d6044472d786936acbd3cd93c7728daa3343b35ccaa5c55eba6b35c28c831bb245b8cdd8fc8cb67a72f57e62a0e1259f5e804c487a8478f6895b302d39277bd73947598a5f8ec0a535be9e9a4d34df91df948ee44cc3d13d14e23b9651089e4767c7f0e7245df55619c92fe24483225d35f5f3ee6f74375065766ffd c1 = 0x27d8d7249643668ffc115be8b61775c60596e51f6313b47ad5af8493526922f5e10026a2cdaef74e22c3eec959dd8771abe3495b18d19f97623f5a3f65f22ff8fc294fc37ceb3b43ebbbf8a9bcf622922e22c5520dbd523483b9dc54fdffcd1a1b3f02ca1f53b75413fb79399ca00034f2acf108ac9a01bd24d2b9df6e27d156 c2 = 0xeaf06b9050a809659f962251b14d6b93009a7010f0e8d8f0fa4d71591757e98243b8ff50ec98a4e140fd8a63bbb4b8bb0a6d302a48845b8b09d1e40874fcb586ddccbb0bbf86d21540ec6c15c1d2bf925942f6f384fdc1baae7f8e06150ccd9459eb65d0f07eea16a911fa0a17e876a145dbfec83537ca2bee4641897b9f7f5 c3 = 0x15be2b0eaef8837a753587c47d3f31696a7d239d88837a9b7d903cd0d0648ef8e225ea555402693a23f305d19e7e13905be61b44c651dba5b26614bcf876234e765a724e0ed8af4a4e408e6a233c48ab9cc63e9c552ef9cd1999512aa0aca830fe6cbcbcc3c6bb354903124a2c3a12d442cdbdefdae6576f4bbc1515051b7111 a = b2l(b'Common prime RSA is a variant of RSA') << 696 b = b2l(b'And the common factor g is large prime and p=2ga+1 q=2gb+1')
mbar = a+b R.<x> = Zmod(n1)[] f = ((2^464) * x + mbar) ^ 3 - c1 f = f.monic() g1 = int(f.small_roots(X=2^230,beta=1)[0])
beta = 2* g1 v = ((n1 - 1) // beta)% beta u = ((n1 - 1) // beta - v) // beta b = pow(2,beta,n1) left = (2*int(sqrt(n1))//beta-2-v)//beta right = (3*int(sqrt(2)*sqrt(n1))//(2*beta) - 2 - v )//beta D = int(sqrt(right - left)) + 1 ############################################################# # 这部分应该是bsgs部分由于没办法跑出结果,无法确定自己的算法是否正确 # # 所以就先不放出来了,想知道具体的可以找d33师傅的博客 # #############################################################
c=left+698170*D+5980588 xy = u - c x_y = v + c * beta x = var('x') f = x^2 - x_y * x + xy x,y = f.roots()[0][0],f.roots()[1][0] p,q = x *beta+1,y*beta+1 assert p*q == n1 g2 = int(pow(c2,int(inverse_mod(65537,(p-1)*(q-1))),n1)) beta = 2 * g2 x_y = ((n2 - 1) // beta)% beta xy = ((n2 - 1) // beta - x_y) // beta x = var('x') f = x^2 - x_y * x + xy x,y = f.roots()[0][0],f.roots()[1][0] p,q = x *beta+1,y*beta+1 assert p*q == n2 l2b(pow(c3,int(inverse_mod(65537,(p-1)*(q-1))),n2))
e = inverse(d, (p-1)*(q-1)) m = bytes_to_long(flag.encode()) c = pow(m, e, N) print('N =', N) print('e =', e) print('c =', c)
''' N = 7194944829894746935571965271122989443610702698015123026500274312320541540511952275333536082176132102091625202863345739074691901574020649953130369453360247690506566827078013306825941200018330639608298539682191482947557146237487451707849833303794107411686130468587672820352641436722348277258977791778239539008852841749667581869688275892813664557078043533743669277649148468667399393518112220602616186358353262921270486781426670131125521444335280904901224934061164334131460273779473387748722008412594372005590209919098686472153912130124772089012962023984089123929555594332030502775588070235834837667605812843128059372243 e = 5872666789397408936685003821802975734744078884385553897196686533187747297681714766542317071546532454504513425295170366015384657690105523240363850101369048640430719519784564240908244756652800934680608667950183962226340288720771217107508516125044088043789281574833079766048266075717484676158307477384862873719462770774288252074344824446884295300603035728339571606659365040029505127532956295163195257002051007447197735267997104725561159289832252522298457628452222155625714679911912616173849423059919537353814530280736653541415686756485413316581322357887750268983241858913704388088485132644523120028234659344174431547087 c = 6601667269134560091452287214083525217696007424340765571114688738279264700361513951309195757650152324371826111195352731779137577044473630747863137747356695892337017953751159248388157498368915463745769509485009626774902347006319659852239932231921393353157319713540010424345134411781723171111939891127671029064626426950125001347122070491553845919803891156107693973027238705710354919725550360159383455222982999904576805089837067774838194257113022653159325313574447189639317397889065351340828031907571541750274329094240472180870714728295651611160552345500801797030280900507979459558944006193012524181456837126192865748097 '''
(Howgrave-Graham) Let f (x, y) be a polynomial that is a sum of at most ω monomial. Suppose f (x0, y 0) = 0 mod pm for some positive integer m, where |x0| ≤ X and |y0| ≤ Y . If || f (xX, yY )|| < pm √ω , then f (x0, y 0) = 0 holds over the integers.
from sage.allimport * from Crypto.Util.number import long_to_bytes N = 7194944829894746935571965271122989443610702698015123026500274312320541540511952275333536082176132102091625202863345739074691901574020649953130369453360247690506566827078013306825941200018330639608298539682191482947557146237487451707849833303794107411686130468587672820352641436722348277258977791778239539008852841749667581869688275892813664557078043533743669277649148468667399393518112220602616186358353262921270486781426670131125521444335280904901224934061164334131460273779473387748722008412594372005590209919098686472153912130124772089012962023984089123929555594332030502775588070235834837667605812843128059372243 e = 5872666789397408936685003821802975734744078884385553897196686533187747297681714766542317071546532454504513425295170366015384657690105523240363850101369048640430719519784564240908244756652800934680608667950183962226340288720771217107508516125044088043789281574833079766048266075717484676158307477384862873719462770774288252074344824446884295300603035728339571606659365040029505127532956295163195257002051007447197735267997104725561159289832252522298457628452222155625714679911912616173849423059919537353814530280736653541415686756485413316581322357887750268983241858913704388088485132644523120028234659344174431547087 c = 6601667269134560091452287214083525217696007424340765571114688738279264700361513951309195757650152324371826111195352731779137577044473630747863137747356695892337017953751159248388157498368915463745769509485009626774902347006319659852239932231921393353157319713540010424345134411781723171111939891127671029064626426950125001347122070491553845919803891156107693973027238705710354919725550360159383455222982999904576805089837067774838194257113022653159325313574447189639317397889065351340828031907571541750274329094240472180870714728295651611160552345500801797030280900507979459558944006193012524181456837126192865748097
beta = 0.34 delta = 0.02 amplification = 2048
X = int(N ** delta) Y = int(N ** (delta + beta))
M = Matrix( [ [N ** 2 * X ** 3, 0, 0, 0], [e * N * X ** 3, -N * X ** 2 * Y, 0, 0], [e ** 2 * X ** 3, -2 * e * X ** 2 * Y, X * Y ** 2, 0], [e ** 3 * X ** 3, -3 * e ** 2 * X ** 2 * Y, 3 * e * X * Y ** 2, -(Y ** 3)], ] ) L = M.LLL()[0] x,y = var('x'),var('y') f = x ** 3*(L[0] // X ** 3) + x ** 2 * y * (L[1] // X**2 // Y)+ x * y ** 2 * (L[2] // X // Y ** 2)+ y ** 3 * (L[3] // Y** 3) print(f.factor())
dp = 636751972323 k = 144242809483056840663075735623298553029680437297789965222541248349475437890222709450048997656976387390752105996145725490546933534602744908786700426835710727511955799912350818546609860818884274334936799981304721460528637717 + 1
assert (e * dp - 1 ) % k == 0 p = (e * dp - 1 ) // k + 1 assert N % p == 0 q = N // p phi = (p - 1) * (q - 1) d = inverse_mod(e,phi) print(long_to_bytes(pow(c,d,N)))