#学活广场 humb1e似乎在旗杆背后探头探脑 secret = bin(bytes_to_long(humble_part))[2:] R.<humb1e> = PolynomialRing(GF(getPrime(50))) R = R.quo(humb1e^30+random.randint(1,2^49)*humb1e+1) look_for_humb1e = [R(humb1e ^ (1500*random.choice([ord('h'),ord('u'),ord('m'),ord('b'),ord('1'),ord('e')]))) if i == '1'else R.random_element() for i in secret]
#都放假了四教还亮着灯?抓到Ech0在躲猫猫的时候偷学密码! secret = bin(bytes_to_long(Ech0_part))[2:] look_for_Ech0 = [prod([j[0]^(j[1]-1)*(j[0]-1) for j in factor(random.getrandbits(100))]) if i == '1'else getPrime(100)-1for i in secret]
#雪下得好大,花圃周围的亮白色身影是Z3r0吗 secret = bin(bytes_to_long(Z3r0_part))[2:] p = getPrime(512) look_for_Z3r0 = [pow(31137,65537,p*getPrime(512)) if i == '1'elsepow(31137,65537,getPrime(512)*getPrime(512)) for i in secret]
#学活广场 humb1e似乎在旗杆背后探头探脑 secret = bin(bytes_to_long(humble_part))[2:] R.<humb1e> = PolynomialRing(GF(getPrime(50))) R = R.quo(humb1e^30+random.randint(1,2^49)*humb1e+1) look_for_humb1e = [R(humb1e ^ (1500*random.choice([ord('h'),ord('u'),ord('m'),ord('b'),ord('1'),ord('e')]))) if i == '1'else R.random_element() for i in secret]
#part1 flag = "" R.<humb1ebar> = PolynomialRing(ZZ) withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao1/here humb1e is.txt","r") as f: c = eval(f.read()) for i inrange(len(c)): if(c.count(c[i]) != 1): flag += "1" else: flag += "0" print(long_to_bytes(int(flag,2)))
#CBCTF{H4ppy_N3wyear
1.2
题目:
1 2 3
#都放假了四教还亮着灯?抓到Ech0在躲猫猫的时候偷学密码! secret = bin(bytes_to_long(Ech0_part))[2:] look_for_Ech0 = [prod([j[0]^(j[1]-1)*(j[0]-1) for j in factor(random.getrandbits(100))]) if i == '1'else getPrime(100)-1for i in secret]
#part2 flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao1/here Ech0 is.txt","r") as f: c = eval(f.read()) for i inrange(len(c)): p = c[i] + 1 if(isPrime(p) and p.bit_length() == 100): flag += "0" else: flag += "1" print(long_to_bytes(int(flag,2)))
#!Hope_y0u_can_h4ve_
1.3
题目:
1 2 3 4
#雪下得好大,花圃周围的亮白色身影是Z3r0吗 secret = bin(bytes_to_long(Z3r0_part))[2:] p = getPrime(512) look_for_Z3r0 = [pow(31137,65537,p*getPrime(512)) if i == '1'elsepow(31137,65537,getPrime(512)*getPrime(512)) for i in secret]
defmatrix_crt(mp,mq,p,q): m = matrix(Zmod(p*q),[[crt([int(mp[i,j]),int(mq[i,j])],[p,q]) for i inrange(2)] for j inrange(2)]) return m
p = getPrime(20) a,b = MatrixGroup(matrix(GF(149),[[41,21],[82,81]])),MatrixGroup(matrix(GF(163),[[41,21],[82,81]])) ma,mb = a.gens()[0],b.gens()[0]
look_for_gtg = [list(matrix_crt(matrix(ZZ,ma^random.randint(1,p)),matrix(ZZ,mb^random.randint(1,p)),149,163)) if i == '1'elselist(matrix(Zmod(149*163),[[random.randint(1,149*163)for _ inrange(2)] for __ inrange(2)])) for i in secret]
defmatrix_crt(mp,mq,p,q): m = matrix(Zmod(p*q),[[crt([int(mp[i,j]),int(mq[i,j])],[p,q]) for i inrange(2)] for j inrange(2)]) return m
p = getPrime(20) a,b = MatrixGroup(matrix(GF(149),[[41,21],[82,81]])),MatrixGroup(matrix(GF(163),[[41,21],[82,81]])) ma,mb = a.gens()[0],b.gens()[0]
look_for_gtg = [list(matrix_crt(matrix(ZZ,ma^random.randint(1,p)),matrix(ZZ,mb^random.randint(1,p)),149,163)) if i == '1'elselist(matrix(Zmod(149*163),[[random.randint(1,149*163)for _ inrange(2)] for __ inrange(2)])) for i in secret]
#part1 flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao2/here gtg is.txt","r") as f: c = eval(f.read())
ord = LCM(148,4428) E = Matrix(Zmod(149*163),[[1,0],[0,1]]) for i inrange(len(c)): if(Matrix(Zmod(149*163),c[i]) ^ ord == E): flag += "1" else: flag += "0" print(long_to_bytes(int(flag,2)))
from secret import p,q n = 7589728368000360290382663172234488251897043335410016881502715294598442607646158403453736522549655542481555536223060519309001243744487805230719883633463721 assert n == p * q and isPrime(p) and isPrime(q) andlen(bin(p)) == 258andlen(bin(q)) == 258
R.<x> = PolynomialRing(Zmod(n))
defroll(mode,i): if mode == 0: return random.randint(1,p*q-1) else: x,y = random.randint(1,2^80),random.randint(1,2^256)*p return R(x+x*y^2+y*x^3) look_for_Art0ne = [roll(1,i) if secret[i] == '1'else roll(0,i) for i inrange(len(secret))]
defshuffle(ll,lr): a = ['0']*len(奶茶_part)*ll+['1']*len(奶茶_part)*lr random.shuffle(a) return a
look_for_奶茶 = [int(''.join(shuffle(5,3)),2)^^secret if i == '1'elseint(''.join(shuffle(3,5)),2)^^secret for i inbin(secret)[2:].rjust(8*len(奶茶_part),'0')]
p = 13692367685268431611 x = [matrix(GF(p),4,4,[random.randint(1,p-1) for i inrange(16)]) for i inrange(7)]
look_for_1manity = [list(sum(random.randint(1,p-1)*j for j in x)) if i == '1'elselist(matrix(GF(p),4,4,[random.randint(1,p-1) for i inrange(16)])) for i in secret]
from secret import p,q n = 7589728368000360290382663172234488251897043335410016881502715294598442607646158403453736522549655542481555536223060519309001243744487805230719883633463721 assert n == p * q and isPrime(p) and isPrime(q) andlen(bin(p)) == 258andlen(bin(q)) == 258
R.<x> = PolynomialRing(Zmod(n))
defroll(mode,i): if mode == 0: return random.randint(1,p*q-1) else: x,y = random.randint(1,2^80),random.randint(1,2^256)*p return R(x+x*y^2+y*x^3) look_for_Art0ne = [roll(1,i) if secret[i] == '1'else roll(0,i) for i inrange(len(secret))]
n = 7589728368000360290382663172234488251897043335410016881502715294598442607646158403453736522549655542481555536223060519309001243744487805230719883633463721
#part1 flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao3/here Art0ne is.txt","r") as f: c = eval(f.read())
PR.<x> = PolynomialRing(Zmod(n)) for i inrange(len(c)): f = x - c[i] res = f.small_roots(X=2^80,beta=0.49) if(res != []): flag += "1" else: flag += "0"
defshuffle(ll,lr): a = ['0']*len(奶茶_part)*ll+['1']*len(奶茶_part)*lr random.shuffle(a) return a
look_for_奶茶 = [int(''.join(shuffle(5,3)),2)^^secret if i == '1'elseint(''.join(shuffle(3,5)),2)^^secret for i inbin(secret)[2:].rjust(8*len(奶茶_part),'0')]
#part2 flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao3/here 奶茶 is.txt","r") as f: c = eval(f.read())
zero_bits = [c[8*i] for i inrange(len(c)//8)]
for i inrange(1,len(c)): count1 = 0 res = 0 for j inrange(len(zero_bits)): res += bin(zero_bits[j] ^^ c[i])[2:].count("1") res /= (len(zero_bits)) if(res > 116): flag += "1" else: flag += "0"
p = 13692367685268431611 x = [matrix(GF(p),4,4,[random.randint(1,p-1) for i inrange(16)]) for i inrange(7)]
look_for_1manity = [list(sum(random.randint(1,p-1)*j for j in x)) if i == '1'elselist(matrix(GF(p),4,4,[random.randint(1,p-1) for i inrange(16)])) for i in secret]
#part3 flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao3/here 1manity is.txt","r") as f: c = eval(f.read())
p = 13692367685268431611 vecs = [] for i inrange(len(c)): temp_vec = [] for j inrange(4): for k inrange(4): temp_vec.append(c[i][j][k]) vecs.append(vector(GF(p),temp_vec))
one_bits = [vecs[0],vecs[-1],vecs[-3],vecs[-4],vecs[-5],vecs[-6],vecs[-7]] M = Matrix(GF(p),one_bits)
flag = "" for i inrange(len(c)): T = M.stack(vecs[i]) if(T.rank() == 7): flag += "1" else: flag += "0"
print(long_to_bytes(int(flag,2)))
#3rest3d_in_fi3ld_you_w0rk_0n}
这一问有个小插曲,其实原本的题目中是:
1
look_for_1manity = [list(sum(random.randint(1,65537)*j for j in x)) if i == '1'elselist(matrix(GF(p),4,4,[random.randint(1,p-1) for i inrange(16)])) for i in secret]
s = [sorted(random.sample([_ for _ inrange(n)],t-1)) for i inrange(len(secret))] look_for_pankas = [H_*vector([random.randint(1,32) if j in s[i] else0for j inrange(n)]) if secret[i] == '1'else vector([random.randint(1,p-1) for j inrange(6)]) for i inrange(len(secret))]
F = GF(2 ** 256, 'z') z = F.gens()[0] P = PolynomialRing(F, 'u, v') u, v = P.gens() PP.<x> = PolynomialRing(F) x = PP.gens()[0]
h = u^2 + u f = u^5 + u^3 + 1 on_curve = v^2 + h*v - f h,f = h(u=x),f(u=x)
H = HyperellipticCurve(f, h) J = H.jacobian()
definit(): while1: try: plain = random.randint(1,2^256) xx = F.fetch_int(plain) y, k = on_curve(u=xx, v=x).roots()[0] assert k == 1 return - xx, y except: continue
look_for_v0id = [(3*J(H(init())))[0] if i == '1'else random.choice([(7*J(H(init())))[0],x^2+F.fetch_int(random.randint(1,2^256))*x+F.fetch_int(random.randint(1,2^256))]) for i in secret]
s = [sorted(random.sample([_ for _ inrange(n)],t-1)) for i inrange(len(secret))] look_for_pankas = [H_*vector([random.randint(1,32) if j in s[i] else0for j inrange(n)]) if secret[i] == '1'else vector([random.randint(1,p-1) for j inrange(6)]) for i inrange(len(secret))]
from Crypto.Util.number import * from sage.modular.overconvergent.hecke_series import ech_form from sage.coding.decoder import Decoder, DecodingError from sage.coding.grs_code import GeneralizedReedSolomonCode
def_repr_(self): return"Key equation decoder for %s" % self.code()
def_partial_xgcd(self, a, b, PolRing): prev_t = PolRing.zero() t = PolRing.one()
prev_r = a r = b
while(r.degree() >= t.degree()): q = prev_r.quo_rem(r)[0] prev_r, r = r, prev_r - q * r prev_t, t = t, prev_t - q * t
return (r, t) def_forney_formula(self, error_evaluator, error_locator): C = self.code() alphas = C.evaluation_points() col_mults = C.parity_column_multipliers() ELPp = error_locator.derivative() F = C.base_ring() zero, one = F.zero(), F.one() e = []
for i inrange(C.length()): alpha_inv = one/alphas[i] if error_locator(alpha_inv) == zero: e.append(-alphas[i]/col_mults[i] * error_evaluator(alpha_inv)/ELPp(alpha_inv)) else: e.append(zero)
return vector(F, e)
defdecode(self,S): C = self.code()
PolRing = C.base_field()['x'] x = PolRing.gen() S = PolRing([i for i in S])
#part2 H = C.parity_check_matrix() D = Syndrome_decode(C) flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao4/here pankas is.txt","r") as f: c = eval(f.read())
for i inrange(len(c)): res = D.decode(S^(-1)*vector(F,c[i])) if(notall(j == 0for j in res)): flag += "1" else: flag += "0"
#part2 H = C.parity_check_matrix() flag = "" withopen(r"/home/tiffany/Desktop/ctf/duomaomao/duomaomao4/here pankas is.txt","r") as f: c = eval(f.read())
for i inrange(len(c)): M = Matrix(ZZ,(H.T*S.T).stack(-vector(F,c[i]))) L = block_matrix([ [identity_matrix(n+1),M], [matrix.zero(r,n+1),identity_matrix(r)*p]]) L[:,-r:] *= p res = L.LLL() if(all(abs(j) < 32for j in res[10])): flag += "1" else: flag += "0"
F = GF(2 ** 256, 'z') z = F.gens()[0] P = PolynomialRing(F, 'u, v') u, v = P.gens() PP.<x> = PolynomialRing(F) x = PP.gens()[0]
h = u^2 + u f = u^5 + u^3 + 1 on_curve = v^2 + h*v - f h,f = h(u=x),f(u=x)
H = HyperellipticCurve(f, h) J = H.jacobian()
definit(): while1: try: plain = random.randint(1,2^256) xx = F.fetch_int(plain) y, k = on_curve(u=xx, v=x).roots()[0] assert k == 1 return - xx, y except: continue
look_for_v0id = [(3*J(H(init())))[0] if i == '1'else random.choice([(7*J(H(init())))[0],x^2+F.fetch_int(random.randint(1,2^256))*x+F.fetch_int(random.randint(1,2^256))]) for i in secret]
deg = 256 F = GF(2 ** deg) z = F.gens()[0] P = PolynomialRing(F, 'u, v') u, v = P.gens() PP.<x> = PolynomialRing(F) x = PP.gens()[0]
h = u^2 + u f = u^5 + u^3 + 1 on_curve = v^2 + h*v - f h,f = h(u=x),f(u=x)
H = HyperellipticCurve(f, h) J = H.jacobian()
definit(): while1: try: plain = random.randint(1,2^deg) xx = F.from_integer(plain) y, k = on_curve(u=xx, v=x).roots()[0] assert k == 1 return - xx, y except: continue
L = GF(2).algebraic_closure() u = (3*J(H(init())))[0] x1,x2 = [r for r in u.change_ring(L).roots(multiplicities=False)]
a = f(x1) b = h(x1) F = a - x*b - x^2 v11,v12 = F.roots(multiplicities=False)
a = f(x2) b = h(x2) F = a - x*b - x^2 v21,v22 = F.roots(multiplicities=False)
PR.<x> = PolynomialRing(L) v = [ PR.lagrange_polynomial([(x1,v11),(x2,v21)]), PR.lagrange_polynomial([(x1,v12),(x2,v21)]), PR.lagrange_polynomial([(x1,v11),(x2,v22)]), PR.lagrange_polynomial([(x1,v12),(x2,v22)]) ] for i in v: print(J(u,i))
F = GF(2 ** 256, 'z') z = F.gens()[0] P = PolynomialRing(F, 'u, v') u, v = P.gens() PP.<x> = PolynomialRing(F) x = PP.gens()[0]
h = u^2 + u f = u^5 + u^3 + 1 on_curve = v^2 + h*v - f h,f = h(u=x),f(u=x)
H = HyperellipticCurve(f, h) J = H.jacobian()
definit(): while1: try: plain = random.randint(1,2^256) xx = F.from_integer(plain) y, k = on_curve(u=xx, v=x).roots()[0] assert k == 1 return - xx, y except: continue
order = 13407807929942597099574024998205846127384782207827457971403006387925941306569427075743805985793764139096494648696821820448189053384542053304334065342873600