1. 程式人生 > 實用技巧 >攻防世界-密碼學-Decrypt-the-Message

攻防世界-密碼學-Decrypt-the-Message

1. 題目資訊

題目要求我們解密附件中的資訊;開啟附件,裡面是一首詩,最後給出需要解密的資訊。

2. 分析

此題考察Poem加密;舉例說明加密過程。
詩:for my purpose holds to sail beyond the sunset, and the baths of all the western stars until I die.
明文:We have run out of cigars, situation desperate.
從詩中選擇5個詞for,sail,all,stars,die,將這些詞中的每個字母排序(相同的不合並),即

f o r s a i l a l
6 12 13 15 1 7 9 2 10
l s t a r s d i e
11 16 18 3 14 17 4 8 5

上表共有18個字母,將明文以18個字母一組分成若干行,最後一行未滿之處用a,b,...進行填充,即

1 2 3 4 5 6 7 8 9
w e h a v e r u n
r s s i t u a t i
t e a b c d e f g
10 11 12 13 14 15 16 17 18
o u t o f c i g a
o n d e s p e r a
h i j k l m n o p

再根據第一個表將各列置換,即eud tdj ...,最後連線起來生成密文。

破解的思路就是從詩中窮舉各種取詞情況,然後進行解密,然後選擇可讀的“明文”,已有人寫好破解的工具

3.解題

將詩與密文分別存為poem.txt,cip.txt並移到與poemcode.py同目錄下,使用工具破解:

$ python poemcode.py poem.txt cip.txt
...
ifytuothikcrnyptorapyisheansnweroyoturprbletheyoulodnotnowkwhatourrobemiuasbcdfgheijklnoprst
ifyouthinkcryptographyistheanswertoyourproblemthenyoudonotknowwhatyourproblemisabcdefghijklmnopqrstu
pakprictiyorhftyselorohyphurbeewterunhwooaywtooonrbpofjhsgkeilncmbrt
...

中間的為明文。