MoeCTF2023_AI
入门指北
Flag = moectf{A_B_C_D} ,官方是建议的不带GPU支持的PyTorch安装指令是:
pip3 A B C D
moectf{install_torch_torchvision_torchaudio}
EZ MLP
import numpy as np
def fc(x, weight, bias):
# return np.matmul(x, weight) + bias矩阵相乘
return np.matmul(weight, x) + bias
def forward(x):
z1 = fc(x, w1, b1)
z2 = fc(z1, w2, b2)
y = fc(z2, w3, b3)
return y
w1 = np.load('npys/w1.npy')
b1 = np.load('npys/b1.npy')
w2 = np.load('npys/w2.npy')
b2 = np.load('npys/b2.npy')
w3 = np.load('npys/w3.npy')
b3 = np.load('npys/b3.npy')
float2chr = lambda f: chr(int(np.round((f + 1) * 255 / 2)))
inputs = np.load('npys/inputs.npy')
flag = ''
for i in range(len(inputs)):
y = forward(inputs[i])
c0 = float2chr(y[0, 0])
c1 = float2chr(y[1, 0])
flag += c0 + c1
print('moectf{' + flag + '}')
# moectf{fR13NdsHlP_15_M491C!}
# Hints:
# > Fix the bug in the code to get the flag, only one line of code needs to be changed.
# > Understand the code and the figure(Example.jpg) before flag submission.
# > Example.jpg is only for tutorial and demonstration, no hidden information contained.
ABC
import numpy as np
from PIL import Image
A = np.load('A.npy')
B = np.load('B.npy')
C = np.load('C.npy')
num_rows, num_cols = A.shape
print(num_rows,num_cols)
num_rows, num_cols = B.shape
print(num_rows,num_cols)
num_rows, num_cols = C.shape
print(num_rows,num_cols)
inputs=np.matmul(A, B)
inputs=np.matmul(inputs, C)
print(inputs)
num_rows, num_cols = inputs.shape
im = Image.new('RGB', (num_rows, num_cols))
white = (255, 255, 255)
black = (0, 0, 0)
for i in range(num_rows):
for j in range(num_cols):
if inputs[i,j]<0:
print("-1",end=" ")
im.putpixel((i, j), black)
else:
print("1",end=" ")
im.putpixel((i, j), white)
print()
im.save("flag.jpg")
moectf{U_C4n_D0_uR_AipH4_B_See_2023}