from Crypto.Util.number import * from tqdm import *
n = 1130559951242142418553461557920917245278152787036994964813122956739956040733223190585188299825937660853090732755660557900622564346469528239989519875434612493124663925800482373019421482927567375862528994310090666571233446002163478309309649223886467303834842172338454971591276606602163799133000582891965785243482166772793400065793927508012418516719549212969303944155066541587875789636798394581666621711612432864870236407912486149901575077993702841083287354610398446101725184000000000000000000000000000000149 e = 65537 g = 1766592252951269548814352411327322447034194093921285273353477875204196603230641896039854934719468650093602325707751568 p = 50254221567892101225665855
#part1 factor n a = 2 m = 2 whileTrue: a = pow(a, m, n) pp = GCD(a-1, n) if pp != 1and pp != n: break m += 1 qq = int(n // pp) phi = (pp-1)*(qq-1) d = inverse(e, phi)
#part2 Get hint0 L = Matrix(Zmod(p),[[9,1], [1,0]]) init = vector(Zmod(p),[1,0]) hint0 = int((L^(g-1)*init)[0])
from Crypto.Util.number import * from flag import flag
defgen_prime(nbit): whileTrue: p = 0 for i inrange(nbit, nbit>>1, -1): p += getRandomRange(0, 2) * 2 ** i p += getRandomNBitInteger(nbit>>3) if isPrime(p): return p
nbit = 512 p, q, r = [gen_prime(nbit) for _ in'012'] e, n = 65537, p * q * r
m = bytes_to_long(flag) c = pow(m, e, n)
print(f'n = {n}') print(f'c = {c}')
n = 306274031191812861390142322943384171567281235901023281150152366709090671749498337889684025397615153433878170972936066715221203963189667691979936604050835848397126937722483985215998814393176118687506861486835225543585451024226910726976901506973151291379128731667011697266671380831373270759872483773774444157994113393807135699243427889953159841567700099682080305355884531709396908787777504205775972655070971179462480070831508541674970198913788578939945648909705829 c = 223849092404967389418032074311452301651293919558152640065438289744845837981617978133447578227300156302182335073619698990940597295177229704048168320777498240448811390343120956888620737076325442001666883042713739861144512318389043548008886406065462992332747911568586879243279225955299270912019379515768839390586943094509691563525269138915388095236050068130199760650753758898265542401663546938899693685809537450793106770047460151231224343501919710408682427560812073
from Crypto.Util.number import * from factordb.factordb import FactorDB from tqdm import * import itertools from gmpy2 import iroot defsmall_roots(f, bounds, m=1, d=None): 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 []
n = 306274031191812861390142322943384171567281235901023281150152366709090671749498337889684025397615153433878170972936066715221203963189667691979936604050835848397126937722483985215998814393176118687506861486835225543585451024226910726976901506973151291379128731667011697266671380831373270759872483773774444157994113393807135699243427889953159841567700099682080305355884531709396908787777504205775972655070971179462480070831508541674970198913788578939945648909705829 c = 223849092404967389418032074311452301651293919558152640065438289744845837981617978133447578227300156302182335073619698990940597295177229704048168320777498240448811390343120956888620737076325442001666883042713739861144512318389043548008886406065462992332747911568586879243279225955299270912019379515768839390586943094509691563525269138915388095236050068130199760650753758898265542401663546938899693685809537450793106770047460151231224343501919710408682427560812073
from Crypto.Util.number import * from factordb.factordb import FactorDB from tqdm import *
n = 306274031191812861390142322943384171567281235901023281150152366709090671749498337889684025397615153433878170972936066715221203963189667691979936604050835848397126937722483985215998814393176118687506861486835225543585451024226910726976901506973151291379128731667011697266671380831373270759872483773774444157994113393807135699243427889953159841567700099682080305355884531709396908787777504205775972655070971179462480070831508541674970198913788578939945648909705829 c = 223849092404967389418032074311452301651293919558152640065438289744845837981617978133447578227300156302182335073619698990940597295177229704048168320777498240448811390343120956888620737076325442001666883042713739861144512318389043548008886406065462992332747911568586879243279225955299270912019379515768839390586943094509691563525269138915388095236050068130199760650753758898265542401663546938899693685809537450793106770047460151231224343501919710408682427560812073