信息系统安全作业

作业要求:

已知一段密文ciphertext.txt采用了单表替换密码,请使用频率分析法,对其进行解密,给出密码表、明文,以及解密过程。

密文ciphertext.txt:

1
RWKJ BYYS O BYMJ JL JPY JPYWJFY O PWZ W EYFD QLLZ KYWJ JPY HRWD BWK EYFD OMJYFYKJOMQ O ZOZ MLJ YMTLD OJ W DLIMQ NWM WMZ W DLIMQ BLNWN BYFY KOJJOMQ VYPOMZ NY JPYD BYFY JWRSOMQ RLIZRD O QLJ EYFD WMQFD O ULIRZ MLJ PYWF JPY WUJLFK O JIFMYZ FLIMZ O RLLSYZ WJ JPY NWM WMZ JPY BLNWM WMQFORD JPYD ZOZ MLJ HWD WMD WJJYMJOLM OM JPY YMZ O ULIRZ MLJ VYWF OJ O JIFMYZ FLIMZ WQWOM O UWMJ PYWF W BLFZ O KWOZ WMQFORD OJK MLMY LX DLIF VIKOMYKK JPY DLIMQ NWM KWOZ FIZYRD JPOK OK W HFOEWJY ULMEYFKWJOLM

明文plaintext.txt

1
LAST WEEK I WENT TO THE THEATRE I HAD A VERY GOOD SEAT THE PLAY WAS VERY INTERESTING I DID NOT ENJOY IT A YOUNG MAN AND A YOUNG WOMAM WERE SITTING BEHIND ME THEY WERE TALKING LOUDLY I GOT VERY ANGRY I COULD NOT HEAR THE ACTORS I TURNED ROUND I LOOKED AT THE MAN AND THE WOMAN ANGRILY THEY DID NOT PAY ANY ATTENTION IN THE END I COULD NOT BEAR IT I TURNED ROUND AGAIN I CANT HEAR A WORD I SAID ANGRILY ITS NONE OF YOUR BUSINESS THE YOUNG MAN SAID RUDELY THIS IS A PRIVATE CONVERSATION

密码表:

明文 密文
A W
B V
C U
D Z
E Y
F X
G Q
H P
I O
J T
K S
L R
M N
N M
O L
P H
Q *
R F
S K
T J
U I
V E
W B
X *
Y D
Z *

解密过程

  • 通过程序分析密文中字母出现的次数和频率:
出现次数 密文字母 概率/%
40 Y 10.44
39 M&J 10.18
37 W 9.66
34 O 8.88
29 L 7.57
23 F 6.00
22 Z 5.74
18 D 4.70
15 K&P 3.92
12 Q 3.13
8 B 2.09
7 N 1.82
5 E&U 1.31
1 X&T&I 0.26
0 A&C&G 0
  • 程序统计密文中的单词:

word

  • 英文字母分析:

英文字母出现的概率按大小排列如下:E T A O I N S H R D L C U M W F G Y P B V K J X Q Z
小词的使用频率:
1-letter: a,i,o
2-letter: of,to,in,is,it,be,as,at
3-letter:the,and,for,are,but,not,you,all
4-letter:that,with,have,this,will,your,from,they
5-letter: which,would,there

如果四字单词词末有两个相同字母,往往是ll

a开头的三字单词只能是and are中的一个;

两个字母的组合中如果出现q*,则*u(q后几乎总是u);

如果一个单词的开头和结尾是同一个字母,最可能的是:s t d

两个都是辅音的双字母组合,常含有ntioouea是最常见的双元音字母组;

如果单词的头两个字母都是辅音,则第二个字母最可能是:rlh

如果一个三次以三个辅音结尾,那最常见的是-ght-tch

  • 综上:

首先可以确定出现次数最多的字母Y所对应的明文是E,其次对于单字母单词可以确定:O对应I,W对应A

由双字母单词和三字母单词推出:J对应T,L对应O,X对应F,K对应S;

之后利用自然语言的文字结合规律进行猜测,得出其他对应关系,得到明文如下:

1
LAST WEEK I WENT TO THE THEATRE I HAD A VERY GOOD SEAT THE PLAY WAS VERY INTERESTING I DID NOT ENJOY IT A YOUNG MAN AND A YOUNG WOMAM WERE SITTING BEHIND ME THEY WERE TALKING LOUDLY I GOT VERY ANGRY I COULD NOT HEAR THE ACTORS I TURNED ROUND I LOOKED AT THE MAN AND THE WOMAN ANGRILY THEY DID NOT PAY ANY ATTENTION IN THE END I COULD NOT BEAR IT I TURNED ROUND AGAIN I CANT HEAR A WORD I SAID ANGRILY ITS NONE OF YOUR BUSINESS THE YOUNG MAN SAID RUDELY THIS IS A PRIVATE CONVERSATION

作业要求:

模仿题1中的加密程序,按autokey密码的处理方法,写出加、解密软件。

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){
int len;//明文长度
int operation;//操作数
char plaintext[128],ciphertext[128],autokey[128],key[16];
while(1){
do{
cout<<"加密:0\n解密:1\n退出:2"<<endl;
cin>>operation;
}
while(operation != 0 && operation != 1);
if(operation == 2){
//退出
return 0;
}
else if(operation == 0){
//加密程序
cout<<"input plaintext:(end with #)"<<endl;
//cin>>plaintext;
cin.getline(plaintext,128,'#');
len = strlen(plaintext);
cout<<"the plaintext is:";
//cout<<len<<endl;
/**
for(int i=0;i<len;i++){
cout<<plaintext[i];
}
*/
cout<<plaintext<<endl;
cout<<"input key:(end with #)"<<endl;
cin.getline(key,16,'#');
//cin>>key;
//生成autokey
int k = strlen(key);
//cout<<key<<endl;
for(int i=0;i<k;i++){
autokey[i]=key[i];
}
for(int i=k;i<len;i++){
autokey[i]=plaintext[i-k+1];
}
cout<<"the autokey is:";
int a = strlen(autokey);
//cout<<a<<endl;
//cout<<autokey;
for(int i=0;i<len;i++){
cout<<autokey[i];
}
//cout<<auto;
cout<<endl;
//cout<<(char)(((int)plaintext[1]+(int)autokey[1])%26+97);
for(int i=0;i<len;i++){
ciphertext[i]=((plaintext[i]-'a'+(int)autokey[i]-'a')%26+'a');
/**
if(plaintext[i]>=65&&plaintext[i]<=90){
plaintext[i]+=32;
ciphertext[i]=((plaintext[i]-97)+(autokey[i]-97))&+97;
}
*/
}
cout<<"the ciphertext is:"<<endl;
for(int i=1;i<len;i++){
cout<<ciphertext[i];
}
cout<<endl;
//cout<<ciphertext<<endl;;
}
else if(operation==1){
//解密程序
cout<<"input the ciphertext:(end with #)"<<endl;
cin.getline(ciphertext,128,'#');
cout<<"the ciphertext is:";
cout<<ciphertext<<endl;
cout<<"input the autokey:"<<endl;
cin.getline(autokey,128,'#');
cout<<"the autokey is:";
cout<<autokey<<endl;
for(int i=0;i<len;i++){
plaintext[i+1]=((ciphertext[i]-autokey[i]+26)%26+'a');
}
cout<<"the plaintext is:"<<endl;
//cout<<plaintext<<endl;
for(int i=2;i<=len;i++){
cout<<plaintext[i];
}
cout<<endl;
}
}
}