#!/usr/bin/env sage n = 84236796025318186855187782611491334781897277899439717384242559751095347166978304126358295609924321812851255222430530001043539925782811895605398187299748256080526691975084042025794113521587064616352833904856626744098904922117855866813505228134381046907659080078950018430266048447119221001098505107823645953039 e = 58337 c = 13646200911032594651110040891135783560995665642049282201695300382255436792102048169200570930229947213493204600006876822744757042959653203573780257603577712302687497959686258542388622714078571068849217323703865310256200818493894194213812410547780002879351619924848073893321472704218227047519748394961963394668
# a, b < 2^20 # h = pb + a = qa + b # n = 2gh + 1 # (n-1)/2 = gh # p - 1 = 2ag | a (n-1) from tqdm import tqdm W = pow(2, n-1, n) w = 1 for a in tqdm(range(1, 2^20)): w = w * W % n p = Integer(gcd(n, w-1)) if p == 1: continue q = n // p if p * q == n: print(a) print('p = %d' % p) print('q = %d' % q) break
import libnum phi = (p-1) * (q-1) d = e.inverse_mod(phi) m = pow(c, d, n) print(libnum.n2s(int(m)))
#!/usr/bin/env sage import os os.environ['TERM'] = 'xterm-256color' from pwn import remote
defV(k, N, A=5): M = matrix(Zmod(N), [ [A, -1], [1, 0] ]) v = vector(Zmod(N), [A, 2]) vk = M^k * v return Integer(vk[1])
deffactorN(N): A = 5 whileTrue: v2n = V(2*N, N, A) g = gcd(v2n-2, N) print('[Log] %d - %d' % (A, g)) if g.nbits() >= 256and is_prime(g): r = g q = (r+1) // 2 p = N // (q * r) if p * q * r == N: return p, q, r A = next_prime(A)
#!/usr/bin/env sage n = 1125214074953003550338693571791155006090796212726975350140792193817691133917160305053542782925680862373280169090301712046464465620409850385467397784321453675396878680853302837289474127359729865584385059201707775238870232263306676727868754652536541637937452062469058451096996211856806586253080405693761350527787379604466148473842686716964601958192702845072731564672276539223958840687948377362736246683236421110649264777630992389514349446404208015326249112846962181797559349629761850980006919766121844428696162839329082145670839314341690501211334703611464066066160436143122967781441535203415038656670887399283874866947000313980542931425158634358276922283935422468847585940180566157146439137197351555650475378438394062212134921921469936079889107953354092227029819250669352732749370070996858744765757449980454966317942024199049138183043402199967786003097786359894608611331234652313102498596516590920508269648305903583314189707679 e = 65537 c = 27126515219921985451218320201366564737456358918573497792847882486241545924393718080635287342203823068993908455514036540227753141033250259348250042460824265354495259080135197893797181975792914836927018186710682244471711855070708553557141164725366015684184788037988219652565179002870519189669615988416860357430127767472945833762628172190228773085208896682176968903038031026206396635685564975604545616032008575709303331751883115339943537730056794403071865003610653521994963115230275035006559472462643936356750299150351321395319301955415098283861947785178475071537482868994223452727527403307442567556712365701010481560424826125138571692894677625407372483041209738234171713326474989489802947311918341152810838321622423351767716922856007838074781678539986694993211304216853828611394630793531337147512240710591162375077547224679647786450310708451590432452046103209161611561606066902404405369379357958777252744114825323084960942810
k = 3 phik = cyclotomic_polynomial(k) Rn_ = PolynomialRing(Zmod(n),'xn')
bits = 64 p = random_prime(2^bits) q = random_prime(2^bits) n = p * q print('p = %d' % p) print('q = %d' % q) print('n = %d' % n)
a = 3 b = 7 Ep = EllipticCurve(Zmod(p), [3, 7]) Eq = EllipticCurve(Zmod(q), [3, 7]) En = EllipticCurve(Zmod(n), [3, 7]) P = Ep.random_element() Q = Eq.random_element() xn = crt([Integer(P.xy()[0]), Integer(Q.xy()[0])], [p, q]) yn = crt([Integer(P.xy()[1]), Integer(Q.xy()[1])], [p, q]) N = En([xn, yn]) phip = Ep.order() phiq = Eq.order() phin = phip * phiq print('phip = %d' % phip) print('phiq = %d' % phiq) print()
try: phip * N except Exception as e: E = e _, n, p, q = [Integer(_) for _ in re.findall(r'\d+', E.args[0])] assert n == p * q print('n = %d' % n) print('p = %d' % p) print('q = %d' % q) print()
try: phiq * N except Exception as e: E = e _, n, p, q = [Integer(_) for _ in re.findall(r'\d+', E.args[0])] assert n == p * q print('n = %d' % n) print('p = %d' % p) print('q = %d' % q)
#!/usr/bin/env sage import re a, b, n, C, leak = [138681122158674534796479818810828100269024674330030901179877002756402543027343312824423418859769980312713625658733, 4989541340743108588577899263469059346332852532421276369038720203527706762720292559751463880310075002363945271507040, 762981334990685089884160169295988791471426441106522959345412318178660817286272606245181160960267776171409174142433857335352402619564485470678152764621235882232914864951345067231483720755544188962798600739631026707678945887174897543, (19591102741441427006422487362547101973286873135330241799412389205281057650306427438686318050682578531286702107543065985988634367524715153650482199099194389191525898366546842016339136884277515665890331906261550080128989942048438965, 728465071542637655949094554469510039681717865811604984652385614821789556549826602178972137405550902004858456181137844771163710123158955524137202319902378503104952106036911634918189377295743976966073577013775200078470659428344462772), 762981334990685089884160169295988791471426441106522959345445792076415993922016249232021560266153453470937452118572318136597282436269660557904217923887981072203978473274822142705255987334355747997513083011853917049784914749699536828] En = EllipticCurve(Zmod(n), [a, b]) C = En(C)
assert leak % 199 == 0 try: (leak // 199) * C except Exception as e: E = e _, n, p, q = [Integer(_) for _ in re.findall(r'\d+', E.args[0])] assert n == p * q print('n = %d' % n) print('p = %d' % p) print('q = %d' % q)