[長安“戰疫”網路安全衛士守護賽]no_cry_no_can
阿新 • • 發佈:2022-01-08
[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="")