from Crypto.Util.number import * from Crypto.Cipher import AES from math import log2 from base64 import * from hashlib import md5 from pslist import ps from r import r from ef import ef deflowbit(x): return x&(-x) s=[] endexnum,endexid=[0]*512,[0]*512 for i inrange(512): s.append(int(log2(lowbit(ps[i])))) endexnum[s[-1]]=ps[i] endexid[s[-1]]=i kount=0 xored=[] for i inrange(512): tmp1,tmp2=(r>>i)&1,(kount>>i)&1 if tmp1^tmp2: xored.append(i) kount^=endexnum[i] p=0 for i in xored: p+=(1<<(511-endexid[i])) key=long_to_bytes(int(md5(long_to_bytes(p)).hexdigest(),16)) aes_obj = AES.new(key, AES.MODE_ECB) ef=b64decode(ef) ef=aes_obj.decrypt(ef) print(ef)
然后我们就拿到了最后的flag:flag{shemir_alotof_in_wctf_fun!}
2.[Zer0pts2020]ROR
先看一下题目
1 2 3 4 5 6 7 8 9 10 11 12
import random from secret import flag ror = lambda x, l, b: (x >> l) | ((x & ((1<<l)-1)) << (b-l)) N = 1 for base in [2, 3, 7]: N *= pow(base, random.randint(123, 456)) e = random.randint(271828, 314159) m = int.from_bytes(flag, byteorder='big') assert m.bit_length() < N.bit_length() for i inrange(m.bit_length()): print(pow(ror(m, i, m.bit_length()), e, N))
from Crypto.Util.number import * from valc import C deff(x): return2021*x**4+2020*x**3+2019*x**2-C L,R=0,1<<5120 while L<=R: M=(L+R)//2 if(f(M)>0): R=M elif(f(M)<0): L=M elif(f(M)==0): print(M) break print(hex(L),hex(R)) for i inrange(3): input()
from Crypto.Util.number import * from given import p,c,dp,e mp1=pow(c,dp,p) mp=pow(c,dp-1,p) for i inrange(2): x=(c-pow(mp1,e))%(p**(i+1)) y=x*mp1*inverse(e,p)%(p**(i+1)) mp1+=y print(long_to_bytes(mp1))
#Sagemath Ver 9.0 from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler as d_gauss flag = bytearray(raw_input()) flag = list(flag) n = len(flag) q = 40961 ## Finite Field of size q. F = GF(q) ## Univariate Polynomial Ring in y over Finite Field of size q R.<y> = PolynomialRing(F) ## Univariate Quotient Polynomial Ring in x over Finite Field of size 40961 with modulus b^n + 1 S.<x> = R.quotient(y^n + 1) defgen_small_poly(): sigma = 2/sqrt(2*pi) d = d_gauss(S, n, sigma) return d() defgen_large_poly(): return S.random_element() ## Public key 1 a = gen_large_poly() ## Secret key s = S(flag) file_out = open("downloads/public_keys.txt", "w") file_out.write("a: " + str(a) + "\n") for i inrange(100): ## Error e = gen_small_poly() ## Public key 2 b = a*s + e file_out.write("b: " + str(b) + "\n") file_out.close()