h = [] #数据太长不放了 n2, e = (83306955879576794663013877605008168868044098017133825299645318248190193317048264072881820370005988750003947150193243887515721618366600840067815060233979700844891922517920583102626051839017559245080706659940160476934158509162580386609219020570769224015646382223549048698724547720177511383657606919026442310347, 65537)
nums = 98 L = matrix(ZZ, 1+nums*2, 1+nums*3) for i inrange(1+nums*2): L[i,i] = 1 for i inrange(nums): L[0,1+nums*2+i] = h[i+2] L[2*i+1,1+nums*2+i] = h[0] L[2*i+2,1+nums*2+i] = h[1] L[:,-nums:] *= 2^512 L = L.LLL()
v,t,u = L[0,0],L[0,1],L[0,2]
from Crypto.Util.number import * from gmpy2 import gcd from itertools import product from tqdm import trange import sys
for i in trange(-10, 10): for j, k in product(range(-10, 10), repeat = 2): a1, a2, a3, b1, b2, b3 = QQ["a1,a2,a3,b1,b2,b3"].gens() #这边要创建在QQ上才组合的出来,创建的ZZ或者模n意义下都不行 # R.<a1, a2, a3, b1, b2, b3> = Zmod(n2)[] f1 = a3 * b2 - a2 * b3 - i * t f2 = a1 * b3 - a3 * b1 - j * u f3 = a2 * b1 - a1 * b2 - k * v poly = [] poly.extend([f1, f2, f3]) gb = Ideal(poly).groebner_basis() #就算这边gro的时候没有组合,也是可以的 if1: L = identity_matrix(3, 3).change_ring(QQ).augment(matrix(3, 1, list(gb)[1].coefficients())) #这边的系数是分数 L[:, -1] *= n2 res2 = L.LLL() #爆破两次,一次是a1 a2 a3的,另一次是b1 b2 b3的 for i1, j1 in product(range(-10, 10), repeat = 2): res = i1 * res2[0] + j1 * res2[1] if res[-1] == 0: a1, a2, a3 = [tmp for tmp in res[:-1:]] A = [a1, a2, a3] ifall(0 < a < 2 ^ 180for a in A): for i2, j2 in product(range(-10, 10), repeat = 2): res_ = i2 * res2[0] + j2 * res2[1] if res_[-1] == 0: b1, b2, b3 = [tmp for tmp in res_[:-1:]] B = [b1, b2, b3] ifall(0 < b < 2 ^ 180for b in B): q = gcd(int(a2 * h[0] - a1 * h[1]), int(n2)) if isPrime(q) and n2 % q == 0: p = n2 // q print(p) print(q) sys.exit()
h = [] n2, e = (93172851530903280665698646277283403375770782366786869783590259544406324214779512142434711869404111971925289742354082360810829087299546165147248989707179460324393397783211164108966147109518988985549892657039106930772151406465434583994101602999929389467925165673484423421034035671458314305110697400859301468773, 65537) C = Matrix(ZZ, 100, 1, h)
defsmall_roots(f, bounds, m=1, d=None):#多元copper ifnot d: d = f.degree() R = f.base_ring() N = R.cardinality() f /= f.coefficients().pop(0) f = f.change_ring(ZZ) G = Sequence([], f.parent()) for i inrange(m + 1): base = N ^ (m - i) * f ^ i for shifts in itertools.product(range(d), repeat=f.nvariables()): g = base * prod(map(power, f.variables(), shifts)) G.append(g) B, monomials = G.coefficient_matrix() monomials = vector(monomials) factors = [monomial(*bounds) for monomial in monomials] for i, factor inenumerate(factors): B.rescale_col(i, factor) B = B.dense_matrix().LLL() B = B.change_ring(QQ) for i, factor inenumerate(factors): B.rescale_col(i, 1 / factor) H = Sequence([], f.parent().change_ring(QQ)) for h infilter(None, B * monomials): H.append(h) I = H.ideal() if I.dimension() == -1: H.pop() elif I.dimension() == 0: roots = [] for root in I.variety(ring=ZZ): root = tuple(R(root[var]) for var in f.variables()) roots.append(root) return roots return []
c1 = 63368761932613842931186496815195302343816278778369820350680016031561260784146601113278597310189098581850115470098152301165931711345761664290778374659249559329035280283494371042474865722891532827897755000275687864176501132925347463999981764475333799411108459578435275445071666229681621879980239595445066509058 c2 = 140716656752513767303521116946576890451843673026395512785448654626202542315377688700861224898499523861864127538750879630242940209696550481440749930737413349006590385507088788522544403872190399702081066036559185560540710792209083159454133923277846222047802642033856060579088825468633118141806144027582327045847 n = 99720459301264425369585053508752620650615199220949113516774395393283229820439564403401565215598525216853592073661811471273389192191888623577728355790122863652012102195901985097819470227052958722886251736017915052150597294398696203295351320367071710305452460786240560165901336595444101053569653201485580740723
R.<ph, qh> = Zmod(n)[] bound = 5 for i in trange(2 ^ bound): for j inrange(2 ^ bound): f = c1 * c2 - c1 * (2 ^ bound * ph + i) - c2 * (2 ^ bound * qh + j) res = small_roots(f, bounds = (2 ^ (512 - bound), 2 ^ (512 - bound)), m = 3, d = 2) if res: for root in res: p = 2 ^ bound * abs(ZZ(root[0])) + i if isPrime(p) and n % p == 0: print(p) sys.exit()