#sage from Crypto.Util.Padding import pad from Crypto.Cipher import AES from hashlib import md5 import os FLAG = os.environ.get("FLAG", "ctfpunk{XXX_FAKE_FLAG_XXX}")
m = 8 n = 16 p = random_prime(2^512) A = matrix(ZZ, m, n, [randint(-8, 8) for _ inrange(m*n)]) alpha = vector(Zmod(p), [randint(0, p-1) for _ inrange(m)]) B = alpha*A key = md5(str(A.LLL()[0]).encode()).digest() c = AES.new(key, AES.MODE_ECB).encrypt(pad(FLAG.encode(), 16)).hex() print(f"{p = }") print(f"{B = }") print(f"{c = }") """ p = 7064984525561049833941455975315226062215100031502799222949438013406933213082068867354036190111862807403852790782169608415945334428256205825536265168993973 B = (6987440969759551353324677044999675737478126165510769544641525950312340465193691011136383575459117912622463499210240058765919716935919792151451368790904779, 538501908287016811770814963869685588636459507797312498284354257994183787357905990712386568881195466207490578273886998862874804517050990895004493276622276, 4124700208764334513441041531109970827407619648924057630248643329941250298226684483835309006912271794287221844326010511009880926888582259293308874125209877, 1615413470791777172379323594442031980292585267892079844004183034341437946970488889566801194517266423798228232900016427804210664190615250548086969042194055, 4453186502956586735169761657773894925807402254863319717550428624608132045603657281631438493339928635626807899844397961244294365141137080375145978997162407, 6565297672673205366900244325925091704172709184740810263912769943991146161592510244188212998365337366799449944806144562811282170199815376100544325738733703, 1082053880848206246726144084651304123017961124487218546982771854226794920852362975101989964225092310302907400526821842093804607949373873172750421436163130, 707884557268649511183729198708049152610268391656383463908475012939759581261144538094163601701830391103878546436147413922244554897338703575756816396973108, 1472673584290904041194662509179596920341470146210177446004553787904580153104167642987022353312828664564561950541911131984067380572588601476553014264896958, 386126396470902821152131060129593655531616414683521247932592997234654538269464964653091784064790712577097306279712523790073065938893701108104371593190803, 2074128829325519904811849727958434498966441498530579789542382644345388219184360798023203260112646258446112696224286738764577717685929070971045878859298331, 5005696223266177218949847645750647510805747805303156551048184881164677033778700367030717404660127773709053114311640483128611645614441966336013368064152709, 499402862374637565500719745355889892944053567112997684075016072023661464527102673694443235571624833161355323814432566640883825055442487521153172951492084, 2644251123569446715688240316036367098663434133248552246336537366670452536527388132412221201540681300060695922122106419325792546232222449697523053183087366, 837532276539709830888899573089652001142615822398174430524163703591884616290441133332639039580178431384615448154994439512821967333004008882702386597272711, 3743627786813483303995800702852963206656602981404111956128499594153025373806112629265678889858113778648805990248747256067691240913712516523978237984936878) c = '409a6ce08fbc0f66667b6d14e593ea8df3dad5052de7ac1ab592b43237fde2d8bae740dbea10b722557c3579126b6cfe' """
from Crypto.Util.Padding import pad from Crypto.Cipher import AES from hashlib import md5
m = 8 n = 16 p = random_prime(2^512) A = matrix(ZZ, m, n, [randint(-8, 8) for _ inrange(m*n)]) alpha = vector(Zmod(p), [randint(0, p-1) for _ inrange(m)]) B = alpha*A B = Matrix(ZZ, 1, 16, B.list())
res1 = L.LLL() M = [] #寻找满足条件的正交向量,一般来说会和我们要求的矩阵(这边是A)一样大,有8组,每组十六个 for i in res1: if i[-1] == 0: M.append(i[:-1]) else: continue M = Matrix(ZZ, 8, 16, M) print(M * A.T)
from Crypto.Util.Padding import pad from Crypto.Cipher import AES from hashlib import md5
m = 8 n = 16 p = random_prime(2^512) A = matrix(ZZ, m, n, [randint(-8, 8) for _ inrange(m*n)]) alpha = vector(Zmod(p), [randint(0, p-1) for _ inrange(m)]) B = alpha*A B = Matrix(ZZ, 1, 16, B.list())
#构造对应的块矩阵 L = block_matrix([ [identity_matrix(16), B.T], [matrix.zero(1, 16), p] ])
res1 = L.LLL() M = [] #寻找满足条件的正交向量,一般来说会和我们要求的矩阵(这边是A)一样大,有8组,每组十六个 for i in res1: if i[-1] == 0: M.append(i[:-1]) else: continue M = Matrix(ZZ, 8, 16, M) # print(M * A.T)
from Crypto.Util.Padding import pad from Crypto.Cipher import AES from hashlib import md5
m = 8 n = 16 p = random_prime(2^512) A = matrix(ZZ, m, n, [randint(-8, 8) for _ inrange(m*n)]) alpha = vector(Zmod(p), [randint(0, p-1) for _ inrange(m)]) B = alpha*A B = Matrix(ZZ, 1, 16, B.list())
#构造对应的块矩阵 L = block_matrix([ [identity_matrix(16), B.T], [matrix.zero(1, 16), p] ])
res1 = L.LLL() M = [] #寻找满足条件的正交向量,一般来说会和我们要求的矩阵(这边是A)一样大,有8组,每组十六个 for i in res1: if i[-1] == 0: M.append(i[:-1]) else: continue M = Matrix(ZZ, 8, 16, M)
from Crypto.Util.Padding import pad from Crypto.Cipher import AES from hashlib import md5
m = 8 n = 16 p = random_prime(2^512) A = matrix(ZZ, m, n, [randint(-8, 8) for _ inrange(m*n)]) alpha = vector(Zmod(p), [randint(0, p-1) for _ inrange(m)]) B = alpha*A B = Matrix(ZZ, 1, 16, B.list())
#构造对应的块矩阵 L = block_matrix([ [identity_matrix(16), B.T], [matrix.zero(1, 16), p] ])
res1 = L.LLL() M = [] #寻找满足条件的正交向量,一般来说会和我们要求的矩阵(这边是A)一样大,有8组,每组十六个 for i in res1: if i[-1] == 0: M.append(i[:-1]) else: continue M = Matrix(ZZ, 8, 16, M)
from sage.modules.free_module_integer import IntegerLattice from Crypto.Cipher import AES from base64 import b64encode from hashlib import * from secret import flag import signal
n = 75 m = 150 r = 10 N = 126633165554229521438977290762059361297987250739820462036000284719563379254544315991201997343356439034674007770120263341747898897565056619503383631412169301973302667340133958109
defgen(n, m, r, N): t1 = [ZZ.random_element(-2^15, 2^15) for _ inrange(n*m)] #75 * 150 t2 = [ZZ.random_element(N) for _ inrange(r*n)] #10 * 75 B = matrix(ZZ, n, m, t1) #75 * 150 L = IntegerLattice(B) A = matrix(ZZ, r, n, t2) #10 * 75 C = (A * B) % N return L, C
from sage.modules.free_module_integer import IntegerLattice from tqdm import trange from itertools import product from Crypto.Cipher import AES from base64 import b64encode, b64decode from hashlib import * import sys
flag = b'flag{mylove_in_summer}' n = 75 m = 150 r = 10 N = 126633165554229521438977290762059361297987250739820462036000284719563379254544315991201997343356439034674007770120263341747898897565056619503383631412169301973302667340133958109
defgen(n, m, r, N): t1 = [ZZ.random_element(-2^15, 2^15) for _ inrange(n*m)] #75 * 150 t2 = [ZZ.random_element(N) for _ inrange(r*n)] #10 * 75 B = matrix(ZZ, n, m, t1) #75 * 150 L = IntegerLattice(B) A = matrix(ZZ, r, n, t2) #10 * 75 C = (A * B) % N return L, C
B_ = [] for i in res2: ifall(j == 0for j in i[-75::]): B_.append(i[:-75:]) B_ = Matrix(ZZ, B_) B_ = IntegerLattice(B_) res3 = B_.reduced_basis
for i in trange(-10, 10): #直接拿到做密钥的话,发现不管基向量方向对不对,都解不出来,很明显要小爆一下 for j, k in product(range(-10, 10), repeat = 2): res = i * res3[0] + j * res3[1] + k * res3[2] key = sha256(str(res).encode()).digest() aes = AES.new(key, AES.MODE_ECB) flag = aes.decrypt(b64decode(ct)) if flag.isascii(): print(flag) sys.exit()
from not2022but2024 import CBC_key from Crypto.Util.Padding import pad
flag = b'flag{}' from Crypto.Cipher import AES from hashlib import sha256 import random
n = 31 m = 80 M = random_prime(2^256) As = [random.randrange(0,M) for i inrange(n)] xs = [random_vector(GF(2),m).change_ring(ZZ) for i inrange(n)] Bs = sum([As[_] * vector(Zmod(M),xs[_]) for _ inrange(n)]).change_ring(ZZ)
from Crypto.Cipher import AES from hashlib import sha256 import random n = 31#行 m = 80#列 M = random_prime(2^256) As = [random.randrange(0,M) for i inrange(n)] xs = [random_vector(GF(2),m).change_ring(ZZ) for i inrange(n)] Bs = sum([As[_] * vector(Zmod(M),xs[_]) for _ inrange(n)]).change_ring(ZZ)
A = Matrix(Zmod(M), 1, 31, As) X = Matrix(Zmod(M), xs) print(Bs.list() == (A * X).list()) #True