flag = os.getenv("LILCTF_FLAG", "LILCTF{default}")
nrows = 16 ncols = 32
A = [[random.randint(1, 1919810) for _ inrange(ncols)] for _ inrange(nrows)] x = [random.randint(1, 114514) for _ inrange(ncols)]
b = [sum(A[i][j] * x[j] for j inrange(ncols)) for i inrange(nrows)] print(A) print(b)
xx = list(map(int, input("Enter your solution: ").strip().split())) if xx != x: print("Oh, your linear algebra needs to be practiced.") else: print("Bravo! Here is your flag:") print(flag)
已知线性方程组Ax = b,其中A是一个16 × 32矩阵,x是一个32维向量,b是一个16维向量,要求解出x。
一个欠定方程组问题,这里我们可以将式子变形为$A * x - 1*b=0 ,我们构造格M
= ( A ,-b) ,y=
from Crypto.Util.number import * import random from Crypto.Cipher import AES import hashlib from Crypto.Util.Padding import pad from secret import flag
p = random.getrandbits(72) assertlen(bin(p)[2:]) == 72
a = [getPrime(90) for _ inrange(72)] b = 0 t = p for i in a: temp = t % 2 b += temp * i t = t >> 1
from Crypto.Cipher import AES from Crypto.Util.number import * import hashlib
M = [] S = ciphertext = ge = Matrix(ZZ,len(M)+1) for i inrange(len(M)): ge[i,i] = 2 ge[i,-1] = M[i] ge[-1,i] = 1 ge[-1,-1] = S Ge = ge.BKZ(block_size=26) #print(Ge) ge = Matrix(ZZ,len(M)+1) for i inrange(len(M)): ge[i,i] = 2 ge[i,-1] = M[i] ge[-1,i] = 1 ge[-1,-1] = S Ge = ge.BKZ(block_size=26) #print(Ge) for row in Ge: m1 = "" if row[-1] != 0orset(row[:-1]) != {-1,1}:#确保求得的最短向量最后位为0并且只包含-1,1两种情况 continue for i in row[:-1]: m1 += str((i+1)//2) p1=int(m1[::-1],2) print(f"p1 = {p1}") key = hashlib.sha256(str(p1).encode()).digest() cipher = AES.new(key, AES.MODE_ECB) msg = cipher.decrypt(ciphertext) print(msg)
Space Travel
1 2 3 4 5 6 7 8 9
from Crypto.Cipher import AES from hashlib import md5 from params import vecs from os import urandom
key = int("".join([vecs[int.from_bytes(urandom(2)) & 0xfff] for _ inrange(50)]), 2)