from Crypto.Util.number import * from flag import flag
defgen_prime(n): res = 1 for i inrange(15): res *= getPrime(n)
return res
if __name__ == '__main__': n = gen_prime(32) e = 65537 m = bytes_to_long(flag) c = pow(m,e,n) print(n) print(c) # 17290066070594979571009663381214201320459569851358502368651245514213538229969915658064992558167323586895088933922835353804055772638980251328261 # 14322038433761655404678393568158537849783589481463521075694802654611048898878605144663750410655734675423328256213114422929994037240752995363595
from secret import flag from Crypto.Util.number import *
p = getPrime(1024) q = getPrime(1024)
d = getPrime(32) e = inverse(d, (p-1)*(q-1)) n = p*q m = bytes_to_long(flag)
c = pow(m,e,n)
print(c) print(e) print(n)
# c = 6755916696778185952300108824880341673727005249517850628424982499865744864158808968764135637141068930913626093598728925195859592078242679206690525678584698906782028671968557701271591419982370839581872779561897896707128815668722609285484978303216863236997021197576337940204757331749701872808443246927772977500576853559531421931943600185923610329322219591977644573509755483679059951426686170296018798771243136530651597181988040668586240449099412301454312937065604961224359235038190145852108473520413909014198600434679037524165523422401364208450631557380207996597981309168360160658308982745545442756884931141501387954248 # e = 8614531087131806536072176126608505396485998912193090420094510792595101158240453985055053653848556325011409922394711124558383619830290017950912353027270400567568622816245822324422993074690183971093882640779808546479195604743230137113293752897968332220989640710311998150108315298333817030634179487075421403617790823560886688860928133117536724977888683732478708628314857313700596522339509581915323452695136877802816003353853220986492007970183551041303875958750496892867954477510966708935358534322867404860267180294538231734184176727805289746004999969923736528783436876728104351783351879340959568183101515294393048651825 # n = 19873634983456087520110552277450497529248494581902299327237268030756398057752510103012336452522030173329321726779935832106030157682672262548076895370443461558851584951681093787821035488952691034250115440441807557595256984719995983158595843451037546929918777883675020571945533922321514120075488490479009468943286990002735169371404973284096869826357659027627815888558391520276866122370551115223282637855894202170474955274129276356625364663165723431215981184996513023372433862053624792195361271141451880123090158644095287045862204954829998614717677163841391272754122687961264723993880239407106030370047794145123292991433
defcontinuedFra(x, y): """计算连分数 :param x: 分子 :param y: 分母 :return: 连分数列表 """ cf = [] while y: cf.append(x // y) x, y = y, x % y return cf
defgradualFra(cf): """计算传入列表最后的渐进分数 :param cf: 连分数列表 :return: 该列表最后的渐近分数 """ numerator = 0 denominator = 1 for x in cf[::-1]: # 这里的渐进分数分子分母要分开 numerator, denominator = denominator, x * denominator + numerator return numerator, denominator
defsolve_pq(a, b, c): """使用韦达定理解出pq,x^2−(p+q)∗x+pq=0 :param a:x^2的系数 :param b:x的系数 :param c:pq :return:p,q """ par = gmpy2.isqrt(b * b - 4 * a * c) return (-b + par) // (2 * a), (-b - par) // (2 * a)
defgetGradualFra(cf): """计算列表所有的渐近分数 :param cf: 连分数列表 :return: 该列表所有的渐近分数 """ gf = [] for i inrange(1, len(cf) + 1): gf.append(gradualFra(cf[:i])) return gf
defwienerAttack(e, n): """ :param e: :param n: :return: 私钥d """ cf = continuedFra(e, n) gf = getGradualFra(cf) for d, k in gf: if k == 0: continue if (e * d - 1) % k != 0: continue phi = (e * d - 1) // k p, q = solve_pq(1, n - phi + 1, n) if p * q == n: return d
c = e = n =
d = wienerAttack(e, n) print(d) m = pow(c, d, n) print(long_to_bytes(m).decode()) # flag{learn_some_continued_fraction_technique#dc16885c}
from Crypto.Util.number import * c = "e9e3eee8f4f7bffdd0bebad0fcf6e2e2bcfbfdf6d0eee1ebd0eabbf5f6aeaeaeaeaeaef2" c = bytes.fromhex(c)
key = ord('f') ^ c[0] # print(key) key = 143 m = [] for i in c: m.append(i ^ key)
print(bytes(m).hex()) flag = "666c61677b7830725f31355f73796d6d337472795f616e645f65347a792121212121217d" print(long_to_bytes(int(flag,16))) #flag{x0r_15_symm3try_and_e4zy!!!!!!}
babyencoding
1 2 3
part 1 of flag: ZmxhZ3tkYXp6bGluZ19lbmNvZGluZyM0ZTBhZDQ= part 2 of flag: MYYGGYJQHBSDCZJRMQYGMMJQMMYGGN3BMZSTIMRSMZSWCNY= part 3 of flag: =8S4U,3DR8SDY,C`S-F5F-C(S,S<R-C`Q9F8S87T`
c = "dd4388ee428bdddd5865cc66aa5887ffcca966109c66edcca920667a88312064" c = bytes.fromhex(c)
mod = 256 m = b"flag"
a = (c[2]-c[1])*gmpy2.invert((m[2]-m[1]),mod) % mod print(a) #a = 17 b = (c[2] - a*m[2]) % mod print(b) #b = 23 flag = [] for i in c: flag.append((i-b)*gmpy2.invert(a,mod) % mod)
print(bytes(flag).hex()) flag = "666c61677b346666316e655f6331706865725f69355f766572795f33617a797d" print(long_to_bytes(int(flag,16))) #flag{4ff1ne_c1pher_i5_very_3azy}
from Crypto.Util.number import long_to_bytes import gmpy2
n = 93172788492926438327710592564562854206438712390394636149385608321800134934361353794206624031396988124455847768883785503795521389178814791213054124361007887496351504099772757164211666778414800698976335767027868761735533195880182982358937211282541379697714874313863354097646233575265223978310932841461535936931 dp = 307467153394842898333761625034462907680907310539113349710634557900919735848784017007186630645110812431448648273172817619775466967145608769260573615221635 c = 52777705692327501332528487168340175436832109866218597778822262268417075157567880409483079452903528883040715097136293765188858187142103081639134055997552543213589467751037524482578093572244313928030341356359989531451789166815462417484822009937089058352982739611755717666799278271494933382716633553199739292089 e =65537
defdp_leak(dp,c,n,e): for i inrange(1,e): t = (dp * e - 1) % i if t == 0: p = (dp * e - 1) // i + 1 if n % p == 0: q = n // p d = gmpy2.invert(e,(p-1)*(q-1)) print(long_to_bytes(pow(c,d,n))) dp_leak(dp,c,n,e) #flag{cd5ff82d-989c-4fbf-9543-3f98ab567546}
不止一个pi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from flag import flag from Crypto.Util.number import * import gmpy2 p = getPrime(1024) q = getPrime(1024) n = p**3*q**2 print("q = ",q) print("p = ",p) m = bytes_to_long(flag.encode()) c = pow(m,65537,n) print("c = ",c)
# q = 115478867870347527660680329271012852043845868401928361076102779938370270670897498759391844282137149013845956612257534640259997979275610235395706473965973203544920469416283181677660262509481282536465796731401967694683575843183509430017972506752901270887444490905891490955975762524187534052478173966117471143713 # p = 171790960371317244087615913047696670778115765201883835525456016207966048658582417842936925149582378305610304505530997833147251832289276125084339614808085356814202236463900384335878760177630501950384919794386619363394169016560485152083893183420911295712446925318391793822371390439655160077212739260871923935217 # c = 4459183928324369762397671605317600157512712503694330767938490496225669985050002776253470841193156951087663107866714426230222002399666306287642591077990897883174134404896800482234781531592939043551832049756571987010173667074168282355520711905659013076509353523088583347373358980842707686611157050425584598825151399870268083867269912139634929397957514376826145870752116583185351576051776627208882377413433140577461314504762388617595282085102271510792305560608934353515552201553674287954987323321512852114353266359364282603487098916608302944694600227628787791876600901537888110093703612414836676571562487005330299996908873589228072982641114844761980143047920770114535924959765518365614709272297666231481655857243004072049094078525569460293381479558148506346966064906164209362147313371962567040047084516510135054571080612077333228195608109065475260832580192321853906138811139036658485688320161530131239854003996457871663456850196483520239675981391047452381998620386899101820782421605287708727667663038905378115235163773867508258208867367314108701855709002634592329976912239956212490788262396106230191754680813790425433763427315230330459349320412354189010684525105318610102936715203529222491642807382215023468936755584632849348996666528981269240867612068382243822300418856599418223875522408986596925018975565057696218423036459144392625166761522424721268971676010427096379610266649911939139451989246194525553533699831110568146220347603627745407449761792135898110139743498767543521297525802809254842518002190381508964357001211353997061417710783337
q = 115478867870347527660680329271012852043845868401928361076102779938370270670897498759391844282137149013845956612257534640259997979275610235395706473965973203544920469416283181677660262509481282536465796731401967694683575843183509430017972506752901270887444490905891490955975762524187534052478173966117471143713 p = 171790960371317244087615913047696670778115765201883835525456016207966048658582417842936925149582378305610304505530997833147251832289276125084339614808085356814202236463900384335878760177630501950384919794386619363394169016560485152083893183420911295712446925318391793822371390439655160077212739260871923935217 c = 4459183928324369762397671605317600157512712503694330767938490496225669985050002776253470841193156951087663107866714426230222002399666306287642591077990897883174134404896800482234781531592939043551832049756571987010173667074168282355520711905659013076509353523088583347373358980842707686611157050425584598825151399870268083867269912139634929397957514376826145870752116583185351576051776627208882377413433140577461314504762388617595282085102271510792305560608934353515552201553674287954987323321512852114353266359364282603487098916608302944694600227628787791876600901537888110093703612414836676571562487005330299996908873589228072982641114844761980143047920770114535924959765518365614709272297666231481655857243004072049094078525569460293381479558148506346966064906164209362147313371962567040047084516510135054571080612077333228195608109065475260832580192321853906138811139036658485688320161530131239854003996457871663456850196483520239675981391047452381998620386899101820782421605287708727667663038905378115235163773867508258208867367314108701855709002634592329976912239956212490788262396106230191754680813790425433763427315230330459349320412354189010684525105318610102936715203529222491642807382215023468936755584632849348996666528981269240867612068382243822300418856599418223875522408986596925018975565057696218423036459144392625166761522424721268971676010427096379610266649911939139451989246194525553533699831110568146220347603627745407449761792135898110139743498767543521297525802809254842518002190381508964357001211353997061417710783337 e = 65537
n = p**3*q**2 phi = p**2*(p-1) * q*(q-1) d = gmpy2.invert(e,phi) m = pow(c,d,n) print(long_to_bytes(m)) #flag{bu_zhi_yige_p1dsaf}
from Crypto.Util.number import * import gmpy2 import hashlib from tqdm import *
n = 113021375625152132650190712599981988437204747209058903684387817901743950240396649608148052382567758817980625681440722581705541952712770770893410244646286485083142929097056891857721084849003860977390188797648441292666187101736281034814846427200984062294497391471725496839508139522313741138689378936638290593969 c = 43054766235531111372528859352567995977948625157340673795619075138183683929001986100833866227688081563803862977936680822407924897357491201356413493645515962458854570731176193055259779564051991277092941379392700065150286936607784073707448630150405898083000157174927733260198355690620639487049523345380364948649 HASH = ["4a8a08f09d37b73795649038408b5f33","03c7c0ace395d80182db07ae2c30f034","e1671797c52e15f763380b45e841ec32","b14a7b8059d9c055954c92674ce60032","e358efa489f58062f10dd7316b65649e","cfcd208495d565ef66e7dff9f98764da","b14a7b8059d9c055954c92674ce60032","8fa14cdd754f91cc6554c9e71929cce7","0cc175b9c0f1b6a831c399e269772661","4a8a08f09d37b73795649038408b5f33","e358efa489f58062f10dd7316b65649e","cfcd208495d565ef66e7dff9f98764da","4b43b0aee35624cd95b910189b3dc231","cbb184dd8e05c9709e5dcaedaa0495cf"]
t = gmpy2.iroot(n,2)[0] p = gmpy2.next_prime(t) q = n // p e = 65537 d = gmpy2.invert(e,(p-1)*(q-1)) m = pow(c,d,n) flag1 = long_to_bytes(m)[:-8]
flag2 = "" for i in trange(len(HASH)): for j inrange(32,128): hash = hashlib.md5(chr(j).encode()).hexdigest() ifhash == HASH[i]: flag2 += chr(j) flag = flag1+ flag2.encode() print(flag) #flag{two_cloabcse_t0_fact0r}
from pwn import * from tqdm import * from sympy.ntheory.modular import * from Crypto.Util.number import * import gmpy2
host = 'node4.buuoj.cn'#ip地址 port = 28352#端口
sh = remote(host,port) #建立连接 N = [] C = []
for i in trange(17): data = sh.recvuntil(b">") # print(data.decode()) sh.sendline(b"1") n = sh.recvline().decode().split('=')[-1] N.append(eval(n)) c = sh.recvline().decode().split('=')[-1] C.append(eval(c)) iflen(N) >= 17: M = crt(N,C) for j in M: m = gmpy2.iroot(int(j),17)[0] flag = long_to_bytes(m) ifb"flag"in flag: print(flag) break break
#flag{d0_n0t_sh0ut_loud1y_1n_th3_d4rk_f0r3st}
Week3
Crypto
Rabin’s RSA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
from Crypto.Util.number import * from secret import flag p = getPrime(64) q = getPrime(64) assert p % 4 == 3 assert q % 4 == 3
n = p * q
e = 2 m = bytes_to_long(flag)
c = pow(m,e,n)
print('n =', n) print('c =', c)
# n = 201354090531918389422241515534761536573 # c = 20442989381348880630046435751193745753
a = (inv_p * p * mq + inv_q * q * mp) % n b = n - int(a) c = (inv_p * p * mq - inv_q * q * mp) % n d = n - int(c) # 因为rabin 加密有四种结果,全部列出。 aa = [a, b, c, d] for i in aa: print(long_to_bytes(int(i))) # flag{r4b1n#4c58}
from Crypto.Util.number import * from secret import * flag_part = flag_content + '#' + secret_token p = getPrime(512) q = getPrime(512)
m = bytes_to_long(flag_part.encode())
e = 5 n = p*q
c = pow(m,e,n)
print('n =', n) print('c =', c) print('flag_part =', flag_part) print() print('--- hint begin ---') print('flag = "flag{" + flag_part + "}"') print('type of secret_token is', type(secret_token)) print('length of secret_token is', len(secret_token))
# n = 131889193322687215946601811511407251196213571687093913054335139712633125177496800529685285401802802683116451016274353008428347997732857844896393358010946452397522017632024075459908859131965234835870443110233375074265933004741459359128684375786221535003839961829770182916778717973782408036072622166388614214899 # c = 11188201757361363141578235564807411583085091933389381887827791551369738717117549969067660372214366275040055647621817803877495473068767571465521881010707873686036336475554105314475193676388608812872218943728455841652208711802376453034141883236142677345880594246879967378770573385522326039206400578260353074379 # flag_part = sm4ll_r00ts_is_brilliant#◼️◼️◼️◼️◼️◼️◼️◼️ # # --- hint begin --- # flag = "flag{" + flag_part + "}" # type of secret_token is <class 'str'> # length of secret_token is 8
只有密文后8位不知道,把已知明文转为整形,然后左移64位,用copper
exp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import gmpy2 from Crypto.Util.number import * n = c = e = 5
flag = b"sm4ll_r00ts_is_brilliant#" m1 = bytes_to_long(flag) m1 = m1 << 64 R.<x> = PolynomialRing(Zmod(n)) f = (m1 + x)^e - c f = f.monic() root = f.small_roots(X = 2^64) print(root) m = m1 + root[0] flag = b"flag{" + long_to_bytes(int(m)) + b"}" print(flag) #flag{sm4ll_r00ts_is_brilliant#cc0dac72}
#!/usr/bin/python3 from secret import flag from Crypto.Util.number import * from random import randrange
p = 64999433139797068147576269731948390094958654326970231465808792590598519729077
a = randrange(2, p) b = randrange(2, p) x = bytes_to_long(flag) menu = ''' Random as a Service with LCG backend Enter your option 1. Reset 2. Get 3. Exit '''
defGetRandom(): global x nx = (a*x + b) % p print(nx) x = nx whileTrue: print(menu) opt = input('> ') try: opt = int(opt) if opt == 1: x = bytes_to_long(flag) elif opt == 2: GetRandom() elif opt == 3: break else: print('invalid option') except Exception as e: print('oh no, something wrong!') print(e)
t = [] for i inrange(1,len(output)): t.append(output[i]-output[i-1])
T = [] for i inrange(1,len(t)-1): T.append(t[i+1]*t[i-1] - t[i]**2)
m = [] for i inrange(len(T)-1): mm = gmpy2.gcd(T[i],T[i+1]) if isPrime(mm): m.append(int(mm)) else: for i inrange(1,100): if isPrime(mm // i): mm = mm // i m.append(int(mm)) break #print(m)
for i in m: if isPrime(i): a = gmpy2.invert(t[0],i) * t[1] % i b = output[1] - a*output[0] % i a_ = gmpy2.invert(a,i)
seed = a_ * (output[0]-b) % i flag = long_to_bytes(seed) ifb'flag'in flag: print(flag) break #flag{lcg_1s_n0t_s3cur3#fb528ba5}
import random import gmpy2 from Crypto.Util.number import * from secret import flag import codecs
m = [int(i) for i inbin(int(codecs.encode(flag, 'hex'), 16))[2:]]
# from ASIS Cyber Security Contest Quals 2014 defmakeKey(n): privKey = [random.randint(1, 4**n)] s = privKey[0] for i inrange(1, n): privKey.append(random.randint(s + 1, 4**(n + i))) s += privKey[i] q = random.randint(privKey[n-1] + 1, 2*privKey[n-1]) r = random.randint(1, q) while gmpy2.gcd(r, q) != 1: r = random.randint(1, q) pubKey = [ r*w % q for w in privKey ] return privKey, q, r, pubKey
Ge = Ge.stack(Ge_last_row) Ge = Ge.augment(Ge_last_col)
X = Ge.LLL()[-1] X = X[:-1]
m = "" for i in X: ifabs(i) == 1: m += "1" ifabs(i) == 0: m += "0" print(m) flag = bytes.fromhex(hex(int(m,2))[2:]) print(flag) #flag{Lattice_reduction#c3662541}
from secret import flag from Crypto.Util.number import *
p = getPrime(1024) q = getPrime(1024)
N = p*p*q
d= inverse(N, (p-1)*(q-1)//GCD(p-1, q-1))
m = bytes_to_long(flag)
c = pow(m, N, N)
print('c =', c) print('N =', N) print('d =', d)
# c = 1653396627113549535760516503668455111392369905404419847336187180051939350514408518095369852411718553340156505246372037811032919080426885042549723125598742783778413642221563616358386699697645814225855089454045984443096447166740882693228043505960011332616740785976743150624114653594631779427044055729185392854961786323215146318588164139423925400772680226861699990332420246447180631417523181196631188540323779487858453719444807515638025771586275969579201806909799448813112034867089866513864971414742370516244653259347267231436131850871346106316007958256749016599758599549180907260093080500469394473142003147643172770078092713912200110043214435078277125844112816260967490086038358669788006182833272351526796228536135638071670829206746835346784997437044707950580087067666459222916040902038574157577881880027391425763503693184264104932693985833980182986816664377018507487697769866530103927375926578569947076633923873193100147751463 # N = 1768427447158131856514034889456397424027937796617829756303525705316152314769129050888899742667986532346611229157207778487065194513722005516611969754197481310330149721054855689646133721600838194741123290410384315980339516947257172981002480414254023253269098539962527834174781356657779988761754582343096332391763560921491414520707112852896782970123018263505426447126195645371941116395659369152654368118569516482251442513192892626222576419747048343942947570016045016127917578272819812760632788343321742583353340158009324794626006731057267603803701663256706597904789047060978427573361035171008822467120148227698893238773305320215769410594974360573727150122036666987718934166622785421464647946084162895084248352643721808444370307254417501852264572985908550839933862563001186477021313236113690793843893640190378131373214104044465633483953616402680853776480712599669132572907096151664916118185486737463253559093537311036517461749439 # d = 20650646933118544225095544552373007455928574480175801658168105227037950105642248948645762488881219576174131624593293487325329703919313156659700002234392400636474610143032745113473842675857323774566945229148664969659797779146488402588937762391470971617163496433008501858907585683428652637958844902909796849080799141999490231877378863244093900363251415972834146031490928923962271054053278056347181254936750536280638321211545167520935870220829786490686826062142415755063724639110568511969041175019898031990455911525941036727091961083201123910761290998968240338217895275414072475701909497518616112236380389851984377079
Ge = Matrix(ZZ,[ [q,0,0,0,0], [0,q,0,0,0], [h,0,1,0,0], [0,h,0,2^1000,0], [0,e,0,0,2^1024] ]) for line in Ge.LLL(): ifabs(line[-1]) == 2^1024: m = abs(line[1]) print(bytes.fromhex(hex(m)[2:])) # flag{Lattice_reduction_magic_on_NTRU#82b08b2d}
from Crypto.Util.number import * from sage.allimport * from secret import flag
p = 75206427479775622966537995406541077245842499523456803092204668034148875719001 a = 40399280641537685263236367744605671534251002649301968428998107181223348036480 b = 34830673418515139976377184302022321848201537906033092355749226925568830384464
defsmooth(N): a = 2 n = 2 whileTrue: a = pow(a, n, N) res = gmpy2.gcd(a - 1, N) if res != 1and res != N: return res n += 1 n= c= e = 196608
p = smooth(n) # print(p) # p = 11104262127139631006017377403513327506789883414594983803879501935187577746510780983414313264114974863256190649020310407750155332724309172387489473534782137699 q = n//p
x0=gmpy2.invert(p,q) x1=gmpy2.invert(q,p) cs = [c] for i inrange(16): ps = [] for c2 in cs: r = pow(c2, (p + 1) // 4, p) s = pow(c2, (q + 1) // 4, q)
x = (r * x1 * q + s * x0 * p) % n y = (r * x1 * q - s * x0 * p) % n if x notin ps: ps.append(x) if n - x notin ps: ps.append(n - x) if y notin ps: ps.append(y) if n - y notin ps: ps.append(n - y) cs = ps
for m in ps: mm = gmpy2.iroot(m,3) if mm[1]: flag = long_to_bytes(mm[0]) print(flag) # flag{new1sstar_welcome_you}
from sage.allimport * from secret import flag import random data = [ord(x) for x in flag]
mod = 0x42 n = 200 p = 5 q = 2**20
defE(): return vector(ZZ, [1 - random.randint(0,p) for _ inrange(n)])
defcreatematrix(): return matrix(ZZ, [[q//2 - random.randint(0,q) for _ inrange(n)] for _ inrange(mod)])
A, B, C= creatematrix(), creatematrix(), creatematrix() x = vector(ZZ, data[0:mod]) y = vector(ZZ, data[mod:2*mod]) z = vector(ZZ, data[2*mod:3*mod]) e = E() b = x*B+y*A+z*C + e res = "" res += "A=" + str(A) +'\n' res += "B=" + str(B) +'\n' res += "C=" + str(C) +'\n' res += "b=" + str(b) +'\n'
Y = A.stack(B).stack(C).stack(e) X = Y.solve_left(b) print(X)
flag = "" for i in X[:-1]: flag += chr(i) print(flag) # congratulations, here is your flag:flag{try_lear1n_wi0h_t1e_error}congratulations, here is your flag:flag{try_lear1n_wi0h_t1e_error}congratulations, here is your flag:flag{try_lear1n_wi0h_t1e_error}
import secrets from secret import flag import zlib
ROUND = 100
LENGTH = 20
print('Extreme hard CRC32 challenge') print('ARE YOU READY')
for i inrange(ROUND): print('ROUND', i, '!'*int(i/75 + 1))
target = secrets.randbits(32)
print('Here is my CRC32 value: ', hex(target))
dat = input('Show me some data > ') raw = bytes.fromhex(dat) if zlib.crc32(raw) == target andlen(raw) == LENGTH: print("GREAT") else: print("OH NO") exit()
print("Congratulation! Here is your flag") print(flag)
from Crypto.Util.number import * import crcsolver import zlib from pwn import *
sh = remote("node4.buuoj.cn",28855) for i inrange(100): data = sh.recvuntil(b"Here is my CRC32 value:") c = eval(sh.recvline().decode()) m = crcsolver.solve(b'_'*20, range(8*20), c, zlib.crc32) message = hex(bytes_to_long(m))[2:].zfill(40) sh.sendlineafter(b"Show me some data >",message) sh.interactive()
defbivariate(pol, XX, YY, kk=4): N = pol.parent().characteristic()
f = pol.change_ring(ZZ) PR, (x, y) = f.parent().objgens()
idx = [(k - i, i) for k inrange(kk + 1) for i inrange(k + 1)] monomials = list(map(lambda t: PR(x ** t[0] * y ** t[1]), idx)) # collect the shift-polynomials g = [] for h, i in idx: if h == 0: g.append(y ** h * x ** i * N) else: g.append(y ** (h - 1) * x ** i * f)
# construct lattice basis M = Matrix(ZZ, len(g)) for row inrange(M.nrows()): for col inrange(M.ncols()): h, i = idx[col] M[row, col] = g[row][h, i] * XX ** h * YY ** i
# Transform LLL-reduced vectors to polynomials H = [(i, PR(0)) for i inrange(B.nrows())] H = dict(H) for i inrange(B.nrows()): for j inrange(B.ncols()): H[i] += PR((monomials[j] * B[i, j]) / monomials[j](XX, YY))
deftran(self, m, inverse = False): ifnot inverse: x = m if x in self.domain_cache: return self.domain_cache[x] whileTrue: y = os.urandom(self.n) if y in self.range_cache:continue self.domain_cache[x] = y self.range_cache[y] = x return y else: y = m if y in self.range_cache: return self.range_cache[y] whileTrue: x = os.urandom(self.n) if x in self.domain_cache:continue self.domain_cache[x] = y self.range_cache[y] = x return x
deffunction1(self, M, inverse): ifnot inverse: L, R = M[:self.block_size], M[self.block_size:] L, R = R, xor(L, self.RO1.tran(R)) L, R = R, xor(L, self.RO1.tran(R)) L, R = R, xor(L, self.RO1.tran(R)) else: L, R = M[:self.block_size], M[self.block_size:] L, R = xor(R, self.RO1.tran(L)), L L, R = xor(R, self.RO1.tran(L)), L L, R = xor(R, self.RO1.tran(L)), L return L+R
deffunction2(self, M, inverse): if inverse ornot inverse: return self.RO2.tran(M)
defroll(self, M, inverse): return [self.function1,self.function2][self.coin](M,inverse)
deffunction1(self, M, inverse): X, T = M[:self.block_size], M[self.block_size:] X = xor(X, T) for _ inrange(2): X = xor(self.PRP1.tran(X, inverse),T) return X
deffunction2(self, M, inverse): return self.PRP2.tran(M, inverse)[:self.block_size]
defroll(self, M, inverse): return [self.function1,self.function2][self.coin](M,inverse)
defroll_challenge(challenge_level, challenge): global roll_left print(f"[+] Challenge Level: {challenge_level}") roll_num = int(input(f"How many times are required to roll for solving {challenge_level}? > ")) roll_left -= roll_num [guess_coin(challenge, roll_num) for _ inrange(33)]
defsolve1(): sh.sendlineafter(b"ow many times are required to roll for solving 1?",str(1).encode()) msg = "a"*32 for _ in trange(33): sh.sendlineafter(b"msg? >",msg.encode()) sh.sendlineafter(b"inverse? >",str(0).encode()) data = sh.recvline().decode().strip() if data[:16] == "a"*16: m = "0" else: m = "1" sh.sendlineafter(b"coin? >",m.encode())
deffunction1(self, M, inverse): ifnot inverse: L, R = M[:self.block_size], M[self.block_size:] L, R = R, xor(L, self.RO1.tran(R)) L, R = R, xor(L, self.RO1.tran(R)) L, R = R, xor(L, self.RO1.tran(R)) else: L, R = M[:self.block_size], M[self.block_size:] L, R = xor(R, self.RO1.tran(L)), L L, R = xor(R, self.RO1.tran(L)), L L, R = xor(R, self.RO1.tran(L)), L return L+R
deffunction2(self, M, inverse): if inverse ornot inverse: return self.RO2.tran(M)
deffunction1(self, M, inverse): X, T = M[:self.block_size], M[self.block_size:] X = xor(X, T) for _ inrange(2): X = xor(self.PRP1.tran(X, inverse),T) return X
deffunction2(self, M, inverse): return self.PRP2.tran(M, inverse)[:self.block_size]
defroll(self, M, inverse): return [self.function1,self.function2][self.coin](M,inverse)
deftran(self, m, inverse = False): ifnot inverse: x = m if x in self.domain_cache: return self.domain_cache[x] whileTrue: y = os.urandom(self.n) if y in self.range_cache:continue self.domain_cache[x] = y self.range_cache[y] = x return y else: y = m if y in self.range_cache: return self.range_cache[y] whileTrue: x = os.urandom(self.n) if x in self.domain_cache:continue self.domain_cache[x] = y self.range_cache[y] = x return x
defsolve5(): sh.sendlineafter(b"ow many times are required to roll for solving 5?",str(48).encode()) for _ in trange(33): C = [] for i inrange(48): msg = hex(48 + i)[2:].encode() sh.sendlineafter(b"msg? >",msg) sh.sendlineafter(b"inverse? >",str(0).encode()) data = sh.recvline().decode().strip() c = bytes.fromhex(data) C.append(c) C_ = set(C) iflen(C) != len(C_): m = "1" else: m = "0" sh.sendlineafter(b"coin? >",m.encode())