BUUCTF [UTCTF2020]hill

希尔加密
这里猜测利用的矩阵n=2
然后根据 wznqca = utflag 解出ABCD (是mod26意义下的!)
然后对应变换即可:

from string import *
s = "duqopfkqnwofdbzgeu"

def Find(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6):
    for c1 in range(26):
        for c2 in range(26):
            for c3 in range(26):
                for c4 in range(26):
                    if(((c1*a1+c2*a4)%26 == b1) and ((c1*a2+c2*a5)%26 == b2) and ((c1*a3+c2*a6)%26 == b3) \
                    and((c3*a1+c4*a4)%26 == b4) and ((c3*a2+c4*a5)%26 == b5) and ((c3*a3+c3*a6)%26 == b6)):
                        return (c1,c2,c3,c4)

c = Find(22,13,2,25,16,0,20,5,0,19,11,6)
A,C,B,D = c[0],c[1],c[2],c[3]
flag = ""
for i in range(0,len(s),2):
    flag += ascii_letters[(A*ascii_letters.index(s[i])+C*ascii_letters.index(s[i+1]))%26]
    flag += ascii_letters[(B*ascii_letters.index(s[i])+D*ascii_letters.index(s[i+1]))%26]

print(flag)
# d4nger0us_c1pherText_qq
# d4uqop0fk_q1nwofDbzg_eu

由于转换只有字母 所以还原要加上大小写以及去掉的字符

posted @ 2023-10-01 22:39  N0zoM1z0  阅读(140)  评论(0编辑  收藏  举报