題目來源:su-ctf-quals-2014
題目描述:解密這段信息!
下載附件,內容如下
The life that I have Is all that I have And the life that I have Is yours. The love that I have Of the life that I have Is yours and yours and yours. A sleep I shall have A rest I shall have Yet death will be but a pause. For the peace of my years In the long green grass Will be yours and yours and yours. decrypted message: emzcf sebt yuwi ytrr ortl rbon aluo konf ihye cyog rowh prhj feom ihos perp twnb tpak heoc yaui usoa irtd tnlu ntke onds goym hmpq
里面是一首詩,最后給出需要解密的信息。
這道題考察Poem Codes,知道了原理后,我們可以使用工具進行解密。
C:\Users\Administrator\Desktop\詩歌密碼>python poemcode.py poem.txt cip.txt
...
ifytuothikcrnyptorapyisheansnweroyoturprbletheyoulodnotnowkwhatourrobemiuasbcdfgheijklnoprst
ifyouthinkcryptographyistheanswertoyourproblemthenyoudonotknowwhatyourproblemisabcdefghijklmnopqrstu
pakprictiyorhftyselorohyphurbeewterunhwooaywtooonrbpofjhsgkeilncmbrt
...
在眾多生成的結果中尋找一個通順的句子那便是flag。
注意:
1.將詩歌與密文分別存為poem.txt,cip.txt並移到與poemcode.py同目錄下,使用工具破解
2.使用python2運行腳本
3.必須把一些特殊的字符去掉,比如詩歌中的“.”,如果不去掉,運行的時候會報錯:IndexError: list assignment index out of range
擴展:Poem Codes——詩歌密碼
詩歌密碼在第二次世界大戰中被廣泛使用,它的工作方式如下:
首先,你需要先記住一首詩歌,它不需要太長,也不需要完整。比如下面這句截取自尤利西斯詩歌的片段就可以。
for my purpose holds to sail beyond the sunset, and the baths of all the western stars until I die.
然后,從中選擇五個詞作為關鍵字:比如“ for”,“ sail”,“ all”,“ stars”,“ die”。
接着,將它們串在一起,然后給字母編號,以“ a”開頭為1,第二個“ a”開頭為2,依此類推;如果沒有第二個“ a”,則“ b”的編號為2;或者 如果沒有“ b”,則“ c”被標記為2,依此類推,直到我們為所有字母編號。結果:

現在,假設我們要對下面這個消息進行加密:We have run out of cigars, situation desperate.
由於我們在詩歌中選中了18個字母,因此我們以18個字母為一組寫出該消息,並用無用的字母填充結尾,如下所示:
注意,在第一個表格(關鍵字表格)中,第一個字母“f”,它的下面是6;第二個字母是“o”,下面是12。
相對應地,在第二個表格(我們填充的分組的消息)中,第六列字母是“eud”,而第12列是“tdk”。
我們一般按照五個字母為一組發送加密消息,這樣可以減少(但當然不能消除)傳輸錯誤。
因此,我們信息的第一部分將是eudtd koekc pmwrt
嘗試手動加密整個消息!您會發現這很容易做到,您還將看到錯誤在何處以及如何產生。
當然,我們還必須告訴接收方,我們選擇了哪五個詞作為關鍵字,分別是第1個,第6個,第14個,第17個和第20個。最簡單的方法是替換字母,因此:“afnqt”將被附加到加密的消息上。然后,接收者可以(大致)遵循相反的步驟來解密消息。
當然,在以上的簡短討論中我們忽略了所有的細微差別。但要知道,用詩歌密碼加密的短消息是很難破解的,尤其是當詩歌很少被用於加密或僅用其加密一次。如果這首詩是經常使用的,或者是眾所周知的,那么破解用它加密的消息就不難了。另外,詩歌密碼具有易用性和易記性的優點,並且不需要任何計算設備。
參考:
http://wmbriggs.com/post/1001/
https://github.com/abpolym/crypto-tools/tree/master/poemcode
