原文發(fā)在BBS上,轉(zhuǎn)載過來,《密碼編碼學與網(wǎng)絡(luò)安全:原理與實踐》上的一道題,課本中提示為隱寫術(shù)
In one of Dorothy Sayers's mysteries, Lord Peter is confronted with the messag
e shown below. He also discovers the key to the message, which is a sequence o
f integers:
7876565434321123434565678788787656543432112343456567878878765654433211234
message:
I thought to see the fairies in the fields, but I saw only the evil elephants
with their black backs. Woe! how that sight awed me! The elves danced all arou
nd and about while I heard voices calling clearly.Ah! how I tried to see-throw
off the ugly cloud-but no blind eye of a mortal was permitted to spy them. So
then came minstrels, having gold trumpets, harps and drums. These played very
loudly beside me, breaking that spell. So the dream vanished, whereat I thank
ed Heaven. I shed many tears before the thin moon rose up, frail and faint as
a sickle of straw. Now though the Enchanter gnash his teeth vainly, yet shall
he return as the spring returns. Oh, wretched man! Hell gapes, Erebus now lies
open. The mouths of Death wait on thy end.
(a) Decrypt the message. [Hint: What is the largest integer value?]
(b) If the algorithm is known but not the key, how secure is the scheme?
(c) If the key is known but not the algorithm, how secure is the scheme?
至少在Google和Baidu上沒找到答案
就做第一問了
寫了一個小程序
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream in("cipher.txt");
string key;
string line;
getline(in, key);
int count = 0;
while (getline(in, line))
{
cout << line.at(key.at(count++) - '1');
}
in.close();
return 0;
}
同時把密文中所有的空格,標點和換行全部刪去,用EmEditor的宏功能將字符串拆分成8個字一行(這個真是個好東東吖,尤其是它的宏錄制功能,用它,比用什么perl寫個腳本處理字符串爽吖,只管按F4鍵就好),生成一個文件cipher.txt
7876565434321123434565678788787656543432112343456567878878765654433211234
Ithought
toseethe
fairiesi
nthefiel
dsbutIsa
wonlythe
evilelep
hantswit
htheirbl
ackbacks
Woehowth
atsighta
wedmeThe
elvesdan
cedallar
oundanda
boutwhil
eIheardv
oicescal
lingclea
rlyAhhow
Itriedto
seethrow
offtheug
lycloudb
utnoblin
deyeofam
ortalwas
permitte
dtospyth
emSothen
camemins
trelshav
inggoldt
rumpetsh
arpsandd
rumsThes
eplayedv
eryloudl
ybesidem
ebreakin
gthatspe
llSothed
reamvani
shedwher
eatIthan
kedHeave
nIshedma
nytearsb
eforethe
thinmoon
roseupfr
ailandfa
intasasi
ckleofst
rawNowth
oughtheE
nchanter
gnashhis
teethvai
nlyyetsh
allheret
urnasthe
springre
turnsOhw
retchedm
anHellga
pesErebu
snowlies
openThem
outhsofD
eathwait
onthyend
然后運行程序,得到如下字符
hesittethbetweenthecherubimstheislesmaybegladtHereofastheriversintHesouth
分割一下
he sitteth between the cherubims.the isles may be glad thereof as the rivers in the south.