from random import randint from gmpy2 import gcd from Crypto.Util.number import * n = 17501785470905115084530641937586010443633001681612179692218171935474388105810758340844015368385708349722992595891293984847291588862799310921139505076364559140770828784719022502905431468825797666445114531707625227170492272392144861677408547696040355055483067831733807927267488677560035243230884564063878855983123740667214237638766779250729115967995715398679183680360515620300448887396447013941026492557540060990171678742387611013736894406804530109193638867704765955683067309269778890269186100476308998155078252336943147988308936856121869803970807195714727873626949774272831321358988667427984601788595656519292763705699 WHATF= 7550872408895903340469549867088737779221735042983487867888690747510707575208917229455135563614675077641314504029666714424242441219246566431788414277587183624484845351111624500646035107614221756706581150918776828118482092241867365644233950852801286481603893259029733993572417125002284605243126366683373762688802313288572798197775563793405251353957529601737375987762230223965539018597115373258092875512799931693493522478726661976059512568029782074142871019609980899851702029278565972205831732184397965899892253392769838212803823816067145737697311648549879049613081017925387808738647333178075446683195899683981412014732 e = 65537 sign = 12029865785359077271888851642408932941748698222400692402967271078485911077035193062225857653592806498565936667868784327397659271889359852555292426797695393591842279629975530499882434299824406229989496470187187565025826834367095435441393901750671657454855301104151016192695436071059013094114929109806658331209302942624722867961155156665675500638029626815869590842939369327466155186891537025880396861428410389552502395963071259114101340089657190695306100646728391832337848064478382298002033457224425654731106858054291015385823564302151351406917158392454536296555530524352049490745470215338669859669599380477470525863815
defdivide_pq(e,d,n): k = e**3*(WHATF-3) - 1 whileTrue: g = randint(2, n-1) t = k whileTrue: if t % 2 != 0: break t //= 2 x = pow(g, t, n) if x > 1and gcd(x-1, n) > 1: p = gcd(x-1, n) return (p, n//p)
p,q = divide_pq(e,WHATF,n) phi = (p-1)*(q-1) d = inverse(e,phi)
msg = pow(sign,e,n) m = msg*inverse(pow(2,e**2+d**2,n),n) %n print(long_to_bytes(m))
from sage.allimport* gift = 10954621221812651197619957228527372749810730943802288293715079353550311138677754821746522832935330138708418986232770630995550582619687239759917418738050269898943719822278514605075330569827210725314869039623167495140328454254640051293396463956732280673238182897228775094614386379902845973838934549168736103799539422716766688822243954145073458283746306858717624769112552867126607212724068484647333634548047278790589999183913 C1 = (1206929895217993244310816423179846824808172528120308055773133254871707902120929022352908110998765937447485028662679732041, 652060368795242052052268674691241294013033011634464089331399905627588366001436638328894634036437584845563026979258880828) C2 = (1819289899794579183151870678118089723240127083264590266958711858768481876209114055565064148870164568925012329554392844153, 1110245535005295568283994217305072930348872582935452177061131445872842458573911993488746144360725164302010081437373324551) C3 = (1112175463080774353628562547288706975571507012326470665917118873336738873653792420189391867408691423887642725415133046354, 1820636035485820691083758790204536675748006232767111209985774382700260408550258280489088658228739971137550264759084468620)
PR.<x> = PolynomialRing(Zmod(gift))
f1 = C1[0]^3 + a*C1[0] + b - C1[1]^2 f2 = C2[0]^3 + a*C2[0] + b - C2[1]^2 f3 = C3[0]^3 + a*C3[0] + b - C3[1]^2 F = [f1,f2,f3] ideal = Ideal(F) I = ideal.groebner_basis() print(I) res=[x.constant_coefficient() for x in I] n = res[2] a = -res[0]%n b = -res[1]%n
from gmpy2 import next_prime from pwn import remote
re = remote('node4.buuoj.cn',26309) re.sendline(b'464052305161') re.recvuntil(b'Here is my gift for you: \n') gift = eval(re.recvline().strip(b'\n').decode()) print(gift) re.interactive()
n0 = 30798082519452208630254982405300548841337042015746308462162479889627080155514391987610153873334549377764946092629701 g = 91289086035117540959154051117940771730039965839291520308840839624996039016929 a = 37624142806112008072206555 defhash(msg): key = bin(a)[2:] n = n0 msg = list(map(ord,msg)) for i inrange(len(msg)): if key[i] == '1': n = g * (2 * n + msg[i]) else: continue n = n & ((1 << 383) - 1) return (n - 0xdeedbeef114514) % (1 << 100)
defcheck(str1,str2): key = bin(a)[2:] test = [] for i inrange(len(key)): if key[i] == '0': test.append(str1[i] == str2[i]) returnall(test)
defhash(msg): key = bin(a)[2:] n = n0 msg = list(map(ord,msg)) for i inrange(len(msg)): if key[i] == '1': n = g * (2 * n + msg[i]) else: continue n = n & ((1 << 383) - 1) return (n - 0xdeedbeef114514) % (1 << 100)