Crypto-Without a Trace

Gone with the wind, can you find my flag? - Anakin

Challenge

def inputs():
    print("[WAT] Define diag(u1, u2, u3. u4, u5)")
    M = [
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
    ]
    for i in range(5):
        try:
            M[i][i] = int(input(f"[WAT] u{i + 1} = "))
        except:
            return None
    return M
def main():
    print("[WAT] Welcome")
    M = inputs()
    if M is None:
        print("[WAT] You tried something weird...")
        return
    elif check(M) == 0:
        print("[WAT] It's not going to be that easy...")
        return

    res = fun(M)
    if res == None:
        print("[WAT] You tried something weird...")
        return
    print(f"[WAT] Have fun: {res}")

The check() calculates the determinant of the matrix and fun() multiplies the flag diagonal matrix with the input diagonal matrix

Let f1,f2,f3,f4,f5 be the flag values and let i1,i2,i3,i4,i5 be the inputs that we provide. Then the trace of the matrix multiplication is

f1*i1 + f2*i2 + f3*i3 + f4*i4 + f5*i5

Since we can't put any of the inputs to be 0 (because the determinant would be 0) , therefore we first put all the inputs as 1, then change each input to 2 and subtract it from the first value to get the flag

from Crypto.Util.number import *
l1 = 2000128101369 #(1,1,1,1,1) 
l2 = 2504408575853 #(2,1,1,1,1)
l3 = 2440285994541 #(1,2,1,1,1)
l4 = 2426159182680 #(1,1,2,1,1)
l5 = 2163980646766 #(1,1,1,2,1)
l6 = 2465934208374 #(1,1,1,1,2)
lt = [l2,l3,l4,l5,l6]
t1=b''
for i in lt:
    t1+=long_to_bytes(i-l1)
print(t1)
b'uiuctf{tr4c1ng_&&_mult5!}'

Last updated