2024.6.29 某行业赛 一道 Crypto+Misc 希尔密码

Hill Cipher(不知道题目叫什么名字)

下载题目附件后打开看到

拖到 010 Editor 提示报错,注意到文件末尾存在字符串,且为三的倍数

同时结合图片名为 hill.png 以及图片中数字的排列,推导可能是 Hill Cipher

Exploit

SageMath's Code

# https://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/classical.html#sage.crypto.classical.HillCryptosystem
from sage.all import *

cryptoflag = 'CLYCOEXMAYHD'

# row major
enc_key = Matrix([
    [
        2,4,5
    ],
    [
        9,2,1
    ],
    [
        3,17,7
    ]
])

# transpose
enc_key = enc_key.transpose()

S = AlphabeticStrings()
H = HillCryptosystem(S, 3)
R = IntegerModRing(26)
M = MatrixSpace(R, 3, 3)
A = M(enc_key)
e = H(A)
# enc = e(S("LAMAISONBLANCHE"))
# print(enc)
# print(type(enc))

print(H.deciphering(A, S(cryptoflag)))

Output:

THISISHILLOK