n = 13431294979312769345517878088407659222785929563176888493659632690735510803353339825485161776891929296355466082338185199541755546384591261208929371208286410559187299345800125302598147388467283782373829399059130130575707550536466670447022349923395822077916588516101640779751198703879200863153859677174339078186779847910915309774616338231020176817201080756103027200290903849975398368943087868140010448011002364291104062990443568049879169811274854879262048473842331319786127894828031613201122015559660817797429013884663990368453887433480357502012963127000535358820517096295714967262963843868885674823702064175405493435873 e = 123589168751396275896312856328164328381265978316578963271231567137825613822284638216416 ct = 159269674251793083518243077048685663852794473778188330996147339166703385101217832722333
诈骗类题目。这个ct长度一看就不对,然后就会发现^其实是异或。
exp:
1 2 3 4 5 6 7 8 9
from Crypto.Util.number import *
n = 13431294979312769345517878088407659222785929563176888493659632690735510803353339825485161776891929296355466082338185199541755546384591261208929371208286410559187299345800125302598147388467283782373829399059130130575707550536466670447022349923395822077916588516101640779751198703879200863153859677174339078186779847910915309774616338231020176817201080756103027200290903849975398368943087868140010448011002364291104062990443568049879169811274854879262048473842331319786127894828031613201122015559660817797429013884663990368453887433480357502012963127000535358820517096295714967262963843868885674823702064175405493435873 e = 123589168751396275896312856328164328381265978316578963271231567137825613822284638216416 ct = 159269674251793083518243077048685663852794473778188330996147339166703385101217832722333
from Crypto.Util.number import getPrime, bytes_to_long, isPrime, long_to_bytes from Crypto.Cipher import AES from Crypto.Util.Padding import pad import hashlib
from Crypto.Util.number import * from Crypto.Cipher import AES import hashlib
ct1 = 196150896308015382573408099004515975466540094705348761587854272630906023749083911008835478259767648401709605726136589590310666858430120235218762651641330953170392784645631801449432061363776229651965539255255795373230255852992805188205639228954217034390731460194284731845705855212209524525682241998203303747513174581513168217999505436596818091279091144718119512522929858750349220346765422769476003604849600128605208123474607256344535541843454810706150705449483256361736428064150792476736751093915251743882647862500622465233906844054109281842278362125589335774364236155483783338907105809549449368926475631824722919958889450225026843225780470131268709445293157749 ct2 = 83507921327913521142443934492559420944369023782917085618978768157512494136296269338031471193927727958060037960270530278173852027186606624474398269053920321522448607751539858355179998108075848593814112217098612017462222420001262248144471923306139580601814218471659969728514600258330312623506466116333593434744460773476488134792248490905628242447603788884700795677619881924772996081377617066055448888668800826281711315468059146518373888252421991592124071284411947405472003802863596010724784730366575751160333120162778945930063499020829492960600318519615351417595308518636794008603089224459556289944808655338805251676963828327517925911000528943113536807796285824 enc_flag = "ac2289b707b174c541cf0952bf3b2057561b0872451444a5bbecf18c007ea20fa2b7c8a1707a74a1657e5adb5c1a417f" m = bytes_to_long(b'we give you this as a gift!') e = 11
p = GCD(m**11-ct1,m**11-ct2) for i inrange(2,1000): while(p % i == 0): p //= i q1 = (m**11-ct1) // p q2 = (m**11-ct2) // p
hint = (p+q) >> 200# I can't be giving you that much! print(f"{hint = }")
output:
1 2 3 4
ct = 20030315247290021934293927354887580426070566017560641204155610658927917290198737029903594702064351773446005018155094643288125396810753014936800515440652855824038470725838848349666236623899089094953181436465435270989651491997801177943499187812270081592263331832916362349716591828106306150603120693022149233534 e = 65537 n = 90166344558664675592644684556355545187373291859609367810958775310181360193141550862577281658089332577942193823477148064165061303827534169112815736618901965700400798345371758370344207077280925015891945591352156370597957742921722432314582261224366498475465730899163137511778647694175484386010210005826793007961 hint = 12227137598952006551839416663729660224872609953685427677011433223002140448682395830146750981200
ct = 20030315247290021934293927354887580426070566017560641204155610658927917290198737029903594702064351773446005018155094643288125396810753014936800515440652855824038470725838848349666236623899089094953181436465435270989651491997801177943499187812270081592263331832916362349716591828106306150603120693022149233534 e = 65537 n = 90166344558664675592644684556355545187373291859609367810958775310181360193141550862577281658089332577942193823477148064165061303827534169112815736618901965700400798345371758370344207077280925015891945591352156370597957742921722432314582261224366498475465730899163137511778647694175484386010210005826793007961 hint = 12227137598952006551839416663729660224872609953685427677011433223002140448682395830146750981200 PR.<x> = PolynomialRing(RealField(1000)) f = x*((hint<<200)-x) - n phigh = int(f.roots()[0][0])
PR.<x> = PolynomialRing(Zmod(n)) f = phigh + x res = f.small_roots(X=2^203, beta=0.4)[0] p = int(phigh + res) q = n // p d = inverse(e,(p-1)*(q-1)) flag = pow(ct, d, n)
print(long_to_bytes(int(flag)))
#nbctf{cr34t1v3_fl4gs_4r3_s0_h4rd_t0_m4k3...}
weckes special dots
题目描述:
1
Will told me "special dots" were the key to a safe future in his senior speech. No one can break this now!
K = 2^2000 L = Matrix(ZZ,9,9+4) for i inrange(4): L[0,i] = es[i]*K L[2*i+1,i] = (Ns[i]+1)*K L[2*i+2,i] = K
T = 2^512 L[0,4] = T for i inrange(1,9): if(i % 2 == 0): L[i,i+4] = 1 else: L[i,i+4] = T res = L.LLL()
x2 = abs(res[0][4]) // T print(iroot(x2,2)[1]) ys2 = [abs(res[0][5+2*i]) // T for i inrange(4)]
t = 0 phi = es[t]*x2 // ys2[t] pplusq = Ns[t]-phi+1 pminusq = iroot(pplusq^2-4*Ns[t],2)[0] p = (pplusq + pminusq) // 2 q = Ns[t] // p
d = inverse(es[t]//8,phi) c = pow(cts[t],d,Ns[t])
PR.<x> = Zmod(p)[] f = x^8 - c resp = f.roots()
PR.<x> = Zmod(q)[] f = x^8 - c resq = f.roots()
from sympy.ntheory.modular import crt #M = crt(n,c)[0] for i in resp: for j in resq: modlist = [p,q] clist = [int(i[0]),int(j[0])] M = crt(modlist,clist)[0] print(long_to_bytes(int(M)))
#nbctf{W3ck3s_t0ld_m3_sp3c14l_d0ts_w3r3_s3cur3}
Leet Crypto Generator
题目描述:
1 2
"For all you cryptoers out there I CAN LCG" - SuperBeetleGamer at his prime nc chal.nbctf.com 30432
p = random_prime(2^256) a, b = 3, 4 E = EllipticCurve(GF(p), [a,b]) G = E.gens()[0]
lcg = LCG(random.randint(0,p), p)
flag = "nbctf{[REDACTED]}" flag_bits = list(map(int, list(str(ascii_to_bin(flag)))))
whileTrue: inp = int(input("Pick an index of a flag bit: ")) assert inp >= 0and inp < len(flag_bits)
if flag_bits[inp] == 0: x = E.random_element() print("I wonder what this is: " + str(x.xy())) elif flag_bits[inp] == 1: x = G*bytes_to_long(flag.encode()) + E.random_element()*int(hashlib.sha256(flag.encode()).hexdigest(), 16) y = lcg.next()*x + G*bytes_to_long(flag.encode()) print("I wonder what this is: " + str(y.xy()))
if flag_bits[inp] == 0: x = E.random_element() print("I wonder what this is: " + str(x.xy())) elif flag_bits[inp] == 1: x = G*bytes_to_long(flag.encode()) + E.random_element()*int(hashlib.sha256(flag.encode()).hexdigest(), 16) y = lcg.next()*x + G*bytes_to_long(flag.encode()) print("I wonder what this is: " + str(y.xy()))
from Crypto.Util.number import * from pwn import * from tqdm import * import time
r = remote("chal.nbctf.com",30432) r.recvline()
#finish gen G first(and get flag length = 232) r.sendline(b"0") r.recvuntil(b"I wonder what this is: ")
#get flag #first get basic time T1 = time.time() for j inrange(100): r.sendline(b"0") r.recvuntil(b"I wonder what this is: ") T2 = time.time() time_0 = T2-T1
#get flag print("Begin!") flag = "" for i inrange(8*6,232): T1 = time.time() for j inrange(100): r.sendline(str(i).encode()) r.recvuntil(b"I wonder what this is: ") T2 = time.time() if(T2-T1 > time_0 + 3): flag += "1" else: flag += "0" if(len(flag) % 8 == 0): print(long_to_bytes(int(flag,2)))