crypto——明文攻击
生活随笔
收集整理的這篇文章主要介紹了
crypto——明文攻击
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
打開壓縮包得到兩個文件夾和兩個文件,其中 encrypt.py 中是加密函數的代碼, flag.enc 中是被加密 的秘鑰, original 中是被打亂的小說片段, encrypt 中是加密并打亂后的小說片段。 分析代碼可知,加密方法使用的是維吉尼亞密碼,所以每次加密只會加密字符串中的字母,所以我們就可 以通過剩下沒加密的字符來匹配明文和密文。 將明文和密文匹配之后,我們可以通過已知明文攻擊快速的得到維吉尼亞密碼的秘鑰。 使用得到的秘鑰解密 flag.enc 文件即可得到秘鑰。
def decrypt(data, key):assert len(data) <= len(key)result = ""for i in range(len(data)):if data[i].isupper():result += chr((ord(data[i]) - ord('A') - key[i] + 26) % 26 + ord('A'))elif data[i].islower():result += chr((ord(data[i]) - ord('a') - key[i] + 26) % 26 + ord('a'))else:result += data[i]return resultm = 'Xiwoihp, Gaeasrvd jsf Sliuwe kkqpd ryix hh gkbh Omxnn ezxbi lvaqxxt nrflh, gpv pt yxx iw nls qioeds li qin bds vnef rts ghe ljez fu iywy vbm bwbe. Eke jvytzjn njps uag fh iujt qxehqqp rvseepu djdmg cep nmooryqzyav uu j gcr, nhag cybl kzvx aqsvvdvujy vm lhk Rmooeqfn eaww pthlowyav btng cpy yhpsnyael ov tae xbbf ufzfpbszk, oshfucs ql pma jol po lcp ysywc. Aa jgz heu vcdzf cmqy oufk pmag umt kcss ljml Fniejxqf' c = 'However, Benjamin and Clover could only be with Boxer after working hours, and it was in the middle of the day when the van came to take him away. The animals were all at work weeding turnips under the supervision of a pig, when they were astonished to see Benjamin come galloping from the direction of the farm buildings, braying at the top of his voice. It was the first time that they had ever seen Benjamin' k = [] for i in range(len(m)):t = ord(m[i]) - ord(c[i])k.append(t)c = "xaawr{B0_d0l_cs0m_'Pp0mn-odn1vpabt_deqzcq'?}" t = decrypt(c, k) print(t)總結
以上是生活随笔為你收集整理的crypto——明文攻击的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Crypto-Danciling lin
- 下一篇: crypto-RSA