Crypto-Determined

"It is my experience that proofs involving matrices can be shortened by 50% if one throws the matrices out." - Emil Artin ( by Anakin)

Challenge

def inputs():
    print("[DET] First things first, gimme some numbers:")
    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],
    ]
    try:
        M[0][0] = p
        M[0][2] = int(input("[DET] M[0][2] = "))
        M[0][4] = int(input("[DET] M[0][4] = "))

        M[1][1] = int(input("[DET] M[1][1] = "))
        M[1][3] = int(input("[DET] M[1][3] = "))

        M[2][0] = int(input("[DET] M[2][0] = "))
        M[2][2] = int(input("[DET] M[2][2] = "))
        M[2][4] = int(input("[DET] M[2][4] = "))

        M[3][1] = q
        M[3][3] = r

        M[4][0] = int(input("[DET] M[4][0] = "))
        M[4][2] = int(input("[DET] M[4][2] = "))
    except:
        return None
    return M
def main():
    print("[DET] Welcome")
    M = inputs()
    if M is None:
        print("[DET] You tried something weird...")
        return
    res = fun(M)
    print(f"[DET] Have fun: {res}")

It is similar to the previous question except instead of trace, they give us the determinant of the matrix with p and q values encoded

Let i1,i2,i3,i4,i5,i6,i7,i8,i9 be the inputs. Then the matrix is

[ p  0 i1  0 i2]
[ 0 i3  0 i4  0]
[i5  0 i6  0 i7]
[ 0  q  0  r  0]
[i8  0 i9  0  0]

We calculate the determinant under the symbolic ring to get a direct equation for the determinant

P.<i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,p,q,r> = PolynomialRing(SR)
M = Matrix([[p,0,i1,0,i2],[0,i3,0,i4,0],[i5,0,i6,0,i7],[0,q,0,r,0],[i8,0,i9,0,0]])
det(M)
i2*i4*i6*i8*q - i1*i4*i7*i8*q - i2*i4*i5*i9*q + i4*i7*i9*p*q - i2*i3*i6*i8*r + i1*i3*i7*i8*r + i2*i3*i5*i9*r - i3*i7*i9*p*r

We can solve for q by setting (i2*i4*i6*i8) = 1 and setting the rest to 0

On solving for q, we can decrypt the flag

from Crypto.Util.number import *
q = 12538849920148192679761652092105069246209474199128389797086660026385076472391166777813291228233723977872612370392782047693930516418386543325438897742835129
n = 158794636700752922781275926476194117856757725604680390949164778150869764326023702391967976086363365534718230514141547968577753309521188288428236024251993839560087229636799779157903650823700424848036276986652311165197569877428810358366358203174595667453056843209344115949077094799081260298678936223331932826351
c = 72186625991702159773441286864850566837138114624570350089877959520356759693054091827950124758916323653021925443200239303328819702117245200182521971965172749321771266746783797202515535351816124885833031875091162736190721470393029924557370228547165074694258453101355875242872797209141366404264775972151904835111
e = 65535
p = n//q
d = inverse(e,(p-1)*(q-1))
print(long_to_bytes(pow(c,d,n)))
b'uiuctf{h4rd_w0rk_&&_d3t3rm1n4t10n}'

Last updated