[长安“战疫”网络安全卫士守护赛]no_cry_no_can

[CRYPTO] no_cry_no_can

cazy{y3_1s_a_h4nds0me_b0y!}

得到py文件

from Crypto.Util.number import*
from secret import flag,key

assert len(key) <= 5 #断言:加密的密钥长度不大于5
assert flag[:5] == b'cazy{' #断言:明文flag的前缀
def can_encrypt(flag,key):
    block_len = len(flag) // len(key) + 1  # '//'运算符的意思是地板除,也就是除法向下取整。
    new_key = key * block_len	#这样做的目的是使加密能够对所有字符都有效
    return bytes([i^j for i,j in zip(flag,new_key)])  #异或加密,这里的zip其实就是取两个字符进行异或

c = can_encrypt(flag,key)
print(c)

# b'<pH\x86\x1a&"m\xce\x12\x00pm\x97U1uA\xcf\x0c:NP\xcf\x18~l'

如上,我已经把整个程序的逻辑标注清楚了。下一步我们把给出的密文进行一个爆破,得到部分密钥,再利用密钥进行解密即可

head = b'cazy{'
cipherbox = [60, 112, 72, 134, 26, 38, 34, 109, 206, 18, 0, 112, 109, 151, 85, 49, 117, 65, 207, 12, 58, 78, 80, 207, 24, 126, 108]
password = []

for i in range(0,5) :#爆破取得密钥
    for j in range(0,256):
        if(head[i] ^ j == cipherbox[i]):
            password.append(j)
for i in range(0,len(cipherbox)):#依赖密钥获取明文
    print(chr(cipherbox[i]^ password[i%5]),end="")
posted @ 2022-01-08 21:05  二氢茉莉酮酸甲酯  阅读(90)  评论(0编辑  收藏  举报