m = bytes_to_long(flag) p, q = get_happy_prime() n = p * q e = 65537 print(n) print(pow(m, e, n)) # 24852206647750545040640868093921252282805229864862413863025873203291042799096787789288461426555716785288286492530194901130042940279109598071958012303179823645151637759103558737126271435636657767272703908384802528366090871653024192321398785017073393201385586868836278447340624427705360349350604325533927890879 # 14767985399473111932544176852718061186100743117407141435994374261886396781040934632110608219482140465671269958180849886097491653105939368395716596413352563005027867546585191103214650790884720729601171517615620202183534021987618146862260558624458833387692782722514796407503120297235224234298891794056695442287
n = 24852206647750545040640868093921252282805229864862413863025873203291042799096787789288461426555716785288286492530194901130042940279109598071958012303179823645151637759103558737126271435636657767272703908384802528366090871653024192321398785017073393201385586868836278447340624427705360349350604325533927890879 c = 14767985399473111932544176852718061186100743117407141435994374261886396781040934632110608219482140465671269958180849886097491653105939368395716596413352563005027867546585191103214650790884720729601171517615620202183534021987618146862260558624458833387692782722514796407503120297235224234298891794056695442287
P.<x> = ZZ[]
t = 1 << 512 whileTrue: f = x ^ 2 - t * x + n rs = f.roots() iflen(rs) > 0: p = rs[0][0] q = n // p assert p * q == n break t += 1 d = inverse_mod(65537, (p - 1) * (q - 1)) m = power_mod(c, d, n) print(long_to_bytes(m).decode()) # XYCTF{3f22f4efe3bbbc71bbcc999a0a622a1a23303cdc}
cipher=[0xdc,0x21,0x94,0x2c,0x4a,0xdf,0x94,0x56,0x1b,0x40,0x03,0xc7,0x47,0x3d,0xf4,0x46,0xca,0xf7,0xd8,0x8b,0x89,0x11,0xeb,0xde,0x71,0xc0,0x71,0x6a,0x67,0xcb,0xa5,0x74,0x60,0xff,0xe6,0x8b,0x84,0xcc,0xea,0x09,0x06,0xdd,0xdf,0xb1,0x9d,0x9a,0x72,0x23] key=[0x84,0x78,0xd7,0x78,0x0c,0xa4,0xf5,0x6e,0x7a,0x24,0x37,0xa4,0x24,0x58,0xd9,0x7f,0xab,0xc4,0xed,0xa6,0xbd,0x20,0xdd,0xe9,0x5c,0xf9,0x14,0x5e,0x56,0xe6,0x95,0x43,0x56,0xca,0xd5,0xe9,0xb1,0xaa,0x8e,0x3e,0x36,0xbb,0xa2,0xbb,0x99,0x9e,0x76,0x27] plain="" for i inrange(len(cipher)): plain+=chr(cipher[i]^key[i]) print(plain)
n = 39332423872740210783246069030855946244104982381157166843977599780233911183158560901377359925435092326653303964261550158658551518626014048783435245471536959844874036516931542444719549997971482644905523459407775392702211086149279473784796202020281909706723380472571862792003687423791576530085747716706475220532321
c = 16938927825234407267026017561045490265698491840814929432152839745035946118743714566623315033802681009017695526374397370343984360997903165842591414203197184946588470355728984912522040744691974819630118163976259246941579063687857994193309554129816268931672391946592680578681270693589911021465752454315629283033043
y = 1813650001270967709841306491297716908969425248888510985109381881270362755031385564927869313112540534780853966341044526856705589020295048473305762088786992446350060024881117741041260391405962817182674421715239197211274668450947666394594121764333794138308442124114744892164155894256326961605137479286082964520217
c = 16938927825234407267026017561045490265698491840814929432152839745035946118743714566623315033802681009017695526374397370343984360997903165842591414203197184946588470355728984912522040744691974819630118163976259246941579063687857994193309554129816268931672391946592680578681270693589911021465752454315629283033043
for mp in GF(p)(c).nth_root(e, all=True): for mq in GF(q)(c).nth_root(e, all=True): m = crt([ZZ(mp), ZZ(mq)], [p, q]) try: res = bytes.fromhex(hex(m)[2:]) if res.isascii(): print(res) except: pass
'''
# b'XYCTF{Rabin_is_so_biggggg!}'
Crypto-factor1
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import gmpy2
import hashlib
from Crypto.Util.number import *
p = getPrime(512) q = getPrime(512) d = getPrime(512) e = gmpy2.invert(d, (p**3 - 1) * (q**3 - 1)) flag = "XYCTF{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}" print(e) print(p * q) # 172005065945326769176157335849432320425605083524943730546805772515111751580759726759492349719668775270727323745284785341119685198468883978645793770975366048506237371435027612758232099414404389043740306443065413069994232238075194102578269859784981454218948784071599231415554297361219709787507633404217550013282713899284609273532223781487419770338416653260109238572639243087280632577902857385265070736208291583497988891353312351322545840742380550393294960815728021248513046077985900158814037534487146730483099151396746751774427787635287611736111679074330407715700153025952858666841328055071403960165321273972935204988906850585454805923440635864200149694398767776539993952528995717480620593326867245714074205285828967234591508039849777840636255379730281105670496110061909219669860172557450779495125345533232776767292561378244884362014224844319802810586344516400297830227894063759083198761120293919537342405893653545157892446163
deffactor_rsa_wiener(N, e): N = Integer(N) e = Integer(e) cf = (e / N).continued_fraction().convergents() for f in cf: k = f.numer() d = f.denom() if k == 0: continue phi_N = ((e * d) - 1) / k b = -(N - phi_N + 1) dis = b ^ 2 - 4 * N if dis.sign() == 1: dis_sqrt = sqrt(dis) p = (-b + dis_sqrt) / 2 q = (-b - dis_sqrt) / 2 if p.is_integer() and q.is_integer() and (p * q) % N == 0: p = p % N q = q % N if p > q: return (p, q) else: return (q, p) e=172005065945326769176157335849432320425605083524943730546805772515111751580759726759492349719668775270727323745284785341119685198468883978645793770975366048506237371435027612758232099414404389043740306443065413069994232238075194102578269859784981454218948784071599231415554297361219709787507633404217550013282713899284609273532223781487419770338416653260109238572639243087280632577902857385265070736208291583497988891353312351322545840742380550393294960815728021248513046077985900158814037534487146730483099151396746751774427787635287611736111679074330407715700153025952858666841328055071403960165321273972935204988906850585454805923440635864200149694398767776539993952528995717480620593326867245714074205285828967234591508039849777840636255379730281105670496110061909219669860172557450779495125345533232776767292561378244884362014224844319802810586344516400297830227894063759083198761120293919537342405893653545157892446163 n=99075185389443078008327214328328747792385153883836599753096971412377366865826254033534293886034828804219037466246175526347014045811852531994537520303063113985486063022444972761276531422538694915030159420989401280012025249129111871649831185047820236417385693285461420040134313833571949090757635806658958193793 print(factor_rsa_wiener(n**3,e)) # p**3 = 1244017062789857764422667689197770411561706061389715742852841131131435478039738844788314076541516819766126607314172841730975726749473298781835130842627454629568985724966925735905579282826322467200321805458818184179125514763621834851652092846169460275768772863952106838841006859603856275880383937805904493971997262155516186649395940112478889012377196708598220178020268381188803264308066063878770942584129304104857476445838035070537472243418121420612877337721035139 # q**3 = 781750817102250814081402150839349648838094352331200646064329593739249658509293014822407869754909590964961253627998562104967609046600602463761387625281775226114093766468854130062539304801906723482222402079346881907551622221610829587775870117982981382377420719340275829723435212262439715988059683115133464900926751096727854874698447640032293397116617936988359535830766353635342613807991926780460233344065075367609934736815239097217192394502104370100558611689435563
n = 143413213355903851638663645270518081058249439863120739973910994223793329606595495141951165221740599158773181585002460087410975579141155680671886930801733174300593785562287068287654547100320094291092508723488470015821072834947151827362715749438612812148855627557719115676595686347541785037035334177162406305243
c = 120440199294949712392334113337541924034371176306546446428347114627162894108760435789068328282135879182130546564535108930827440004987170619301799710272329673259390065147556073101312748104743572369383346039000998822862286001416166288971531241789864076857299162050026949096919395896174243383291126202796610039053
for LEN inrange(20,40): low_m = hash(str(LEN)) Copper(low_m, n, c, LEN) # root = b'!__d3ng__hu0__1@n__3h@n__Chu__!}'
import random from Crypto.Util.number import * from secrets import flag
defget_happy_prime(): while1: p = int("".join([random.choice("123") for _ inrange(512)])) q = int("".join([random.choice("567") for _ inrange(512)])) if isPrime(p) and isPrime(q): return (p,q)
m = bytes_to_long(flag) p ,q= get_happy_prime() n = p * q e = 65537 print(n) print(pow(m, e, n)) # 697906506747097082736076931509594586899561519277373830451275402914416296858960649459482027106166486723487162428522597262774248272216088755005277069446993003521270487750989061229071167729138628583207229945902389632065500739730301375338674342457656803764567184544685006193130563116558641331897204457729877920989968662546183628637193220770495938729301979912328865798266631957128761871326655572836258178871966196973138373358029531478246243442559418904559585334351259080578222274926069834941166567112522869638854253933559832822899069320370733424453856240903784235604251466010104012061821038897933884352804297256364409157501116832788696434711523621632436970698827611375698724661553712549209133526623456888111161142213830821361143023186927163314212097199831985368310770663850851571934739809387798422381702174820982531508641022827776262236373967579266271031713520262606203067411268482553539580686495739014567368858613520107678565628269250835478345171330669316220473129104495659093134763261751546990704365966783697780787341963138501 # 153383826085102296581238539677668696644156148059026868813759015106139131297135097831661048493079405226972222492151356105759235749502324303047037349410709021152255315429280760639113724345836532087970918453353723090554450581657930847674930226113840172368662838756446364482977092478979838209396761279326533419699056209983721842484996150025403009644653678928025861445324715419893797015875541525590135843027312322236085581571452084477262582966972702577136904385741443870527205640874446616413917231260133364227248928492574610248881137364204914001412269740461851747883355414968499272944590071623223603501698004227753335552646715567802825755799597955409228004284739743749531270833084850113574712041224896044525292591264637452797151098802604186311724597450780520140413704697374209653369969451501627583467893160412780732575085846467289134920886789952338174193202234175299652687560232593212131693456966318670843605238958724126368185289703563591477049105538528244632434869965333722691837462591128379816582723367039674028619947057144546
from itertools import product from Crypto.Util.number import long_to_bytes
n = 697906506747097082736076931509594586899561519277373830451275402914416296858960649459482027106166486723487162428522597262774248272216088755005277069446993003521270487750989061229071167729138628583207229945902389632065500739730301375338674342457656803764567184544685006193130563116558641331897204457729877920989968662546183628637193220770495938729301979912328865798266631957128761871326655572836258178871966196973138373358029531478246243442559418904559585334351259080578222274926069834941166567112522869638854253933559832822899069320370733424453856240903784235604251466010104012061821038897933884352804297256364409157501116832788696434711523621632436970698827611375698724661553712549209133526623456888111161142213830821361143023186927163314212097199831985368310770663850851571934739809387798422381702174820982531508641022827776262236373967579266271031713520262606203067411268482553539580686495739014567368858613520107678565628269250835478345171330669316220473129104495659093134763261751546990704365966783697780787341963138501 e = 65537 ciphertext = 153383826085102296581238539677668696644156148059026868813759015106139131297135097831661048493079405226972222492151356105759235749502324303047037349410709021152255315429280760639113724345836532087970918453353723090554450581657930847674930226113840172368662838756446364482977092478979838209396761279326533419699056209983721842484996150025403009644653678928025861445324715419893797015875541525590135843027312322236085581571452084477262582966972702577136904385741443870527205640874446616413917231260133364227248928492574610248881137364204914001412269740461851747883355414968499272944590071623223603501698004227753335552646715567802825755799597955409228004284739743749531270833084850113574712041224896044525292591264637452797151098802604186311724597450780520140413704697374209653369969451501627583467893160412780732575085846467289134920886789952338174193202234175299652687560232593212131693456966318670843605238958724126368185289703563591477049105538528244632434869965333722691837462591128379816582723367039674028619947057144546
defbase10(ss): r = 0 for x in ss[::-1]: r = r * 10 + x return r
defdfs(ps, qs, mod): if base10(ps) * base10(qs) == n: yield base10(ps), base10(qs) return for pp, qq in product((1,2,3), (5,6,7)): p = base10(ps + [pp]) q = base10(qs + [qq]) if p * q % mod == n % mod: yieldfrom dfs(ps + [pp], qs + [qq], mod * 10)
flag = b'XYCTF{*****}' m = bytes_to_long(flag) defgainPrime(): whileTrue: x = random.getrandbits(256) y = random.getrandbits(256) if y % 2 == 0: continue p = x ** 3 + 3 * y ** 3 if p.bit_length() == 768and p % 2 == 1and isPrime(p): return p
p, q = gainPrime(), gainPrime() N = p * q phi = (p ** 2 + p + 1) * (q ** 2 + q + 1) d = getPrime(320) e = inverse(d, phi) c = d**2^m
classContinuedFraction(): def__init__(self, numerator, denumerator): self.numberlist = [] # number in continued fraction self.fractionlist = [] # the near fraction list self.GenerateNumberList(numerator, denumerator) self.GenerateFractionList()
defcomplex_pow(c, exp, n): result = Complex(1, 0) while exp > 0: if exp & 1: result = result * c result.re = result.re % n result.im = result.im % n c = c * c c.re = c.re % n c.im = c.im % n exp >>= 1 return result
flag = flag.strip(b"XYCTF{").strip(b"}") p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027 g = Complex(3, 7) x = bytes_to_long(flag) print(complex_pow(g, x, p)) # 5699996596230726507553778181714315375600519769517892864468100565238657988087817 + 198037503897625840198829901785272602849546728822078622977599179234202360717671908i
from Crypto.Util.number import * g = 3^2+7^2 c = 5699996596230726507553778181714315375600519769517892864468100565238657988087817^2 + 198037503897625840198829901785272602849546728822078622977599179234202360717671908^2 p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027 print(long_to_bytes(discrete_log(mod(c,p),mod(g,p)))) # b'___c0mp13x_d1p_15_3@5y_f0r_y0u___'
from Crypto.Util.number import * p = 1849790472911267366045392456893126092698743308291512220657006129900961168811898822553602045875909 A = [[9,0,-36],[6,0,-27],[0,1,0]] n = 3 G = matrix(GF(p), n, n, A) G_Jor, P = G.jordan_form(transformation=True) print(G_Jor) X=[69,48,52] Y=[1431995965813617415860695748430644570118959991271395110995534704629241309597572003500157255135707,1011565891130611736600822618382801465506651972373410962205810570075870804325974377971089090196019,784497518859893244278116222363814433595961164446277297084989532659832474887622082585456138030246] G_2=(~P*matrix(GF(p),3,1,X)) G_3=(~P*matrix(GF(p),3,1,Y))
defGCD(a, b): print(a.degree(), b.degree()) q, r = a.quo_rem(b) if r == 0: return b R00, R01, R10, R11 = HGCD(a, b) c = R00 * a + R01 * b d = R10 * a + R11 * b if d == 0: return c.monic() q, r = c.quo_rem(d) if r == 0: return d return GCD(d, r)
PR.<x> = PolynomialRing(Zmod(n)) f1 = sum(k*x**i for i, k inenumerate(final))^((1<<7)-1) - c1 f2 = x^((1<<16)+1) - c2 f2 = f2 % f1 res = GCD(f1,f2)
m = -res.monic().coefficients()[0] flag = long_to_bytes(int(m)) print(flag)
N = 26278624299187148406559772770865336226934633734285979741424867540828670397865189685966828527168795621543490979182417570078991930822041468539855006585233692884235331084907340302530060261742100702658312435180527335101284800616106884692498603300926488358017928867672861988448488439356448543527810620591324774111321619391264173779312033252573140028630441135269056099074531502841259940379636699304810677716177080486265721322966814104627525953974143476452058638927511594884002185219080847495835727300670028011001853179659250270200020884333850083063514830095064730932997593930711871108436386821290545084229347398808220810263 c = 3335299537518434350008670067273514020883265809787658909900831303201069228111667477512288715627313377374377192065531931991830331266940281529429758933125645068623703704431432931062515459304407129764836169638068667723468109909932687335727824459807903558617156661138991973933280805156893120951135488168923425258119689993859896540097318197048436676318334502053269738046279338047497258783747007084564814994803144049365117574904704816542523015746396519693505167963245600047742456478545640334467678554748227823020862550712083249012329745708139070338928730226897923885785783461594034339595106377701306570280371612953393097739
import itertools import hashlib from Crypto.Util.number import * defsmall_roots(f, bounds, m, 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)
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 []