Skip to content

Commit 2a581ff

Browse files
committed
增加注释
1 parent f499abc commit 2a581ff

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

Encryption/DES.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DES {
1010
public:
1111
string plaintext = "";
1212
string ciphertext = "";
13+
1314
DES(string keyword) {
1415
if (keyword.size() < 8)
1516
{
@@ -22,10 +23,10 @@ class DES {
2223
ciphertext = "";
2324
char plainchar[12];
2425
char cipherchar[12] = "";
25-
for (unsigned int i = 0; i < plaintext.size(); i += 8) {
26-
strcpy(plainchar, plaintext.substr(i, 8).c_str());
27-
memset(cipherchar, 0, sizeof(plainchar));
28-
Run(cipherchar, plainchar, true); //因为是对称加密
26+
for (unsigned int i = 0; i < plaintext.size(); i += 8) { //把明文按每8个字节分割
27+
strcpy(plainchar, plaintext.substr(i, 8).c_str());
28+
memset(cipherchar, 0, sizeof(plainchar)); //把cipherchar每一位赋值0
29+
Run(cipherchar, plainchar, true); //获取对应密文
2930
ciphertext += cipherchar;
3031
}
3132
return ciphertext;
@@ -36,9 +37,9 @@ class DES {
3637
char plainchar[12];
3738
char cipherchar[12];
3839
for (unsigned int i = 0; i < ciphertext.size(); i += 8) {
39-
strcpy(cipherchar, ciphertext.substr(i, 8).c_str());
40+
strcpy(cipherchar, ciphertext.substr(i, 8).c_str()); //把密文按每8个字节分割
4041
memset(plainchar, 0, sizeof(cipherchar));
41-
Run(plainchar, cipherchar, false); //因为是对称加密
42+
Run(plainchar, cipherchar, false); //获取对应明文
4243
plaintext += plainchar;
4344
}
4445
return plaintext;
@@ -51,14 +52,14 @@ class DES {
5152
{
5253
Key[i] = keyword[i];
5354
}
54-
static bool K[64], *KL = &K[0], *KR = &K[28];
55-
charToByte(K, Key, 64); //从char转换到二进制数组
56-
Transform(K, K, PC_1Table, 56); //从64位化为56位
55+
static bool K[64], *KL = &K[0], *KR = &K[28]; //kl,kr分别为左侧和右侧子密码段
56+
charToByte(K, Key, 64); //从char转换到二进制数组
57+
Transform(K, K, PC_1Table, 56); //从64位化为56位
5758
for (int i = 0; i < 16; i++)
5859
{
59-
shiftLeft(KL, 28, shiftTable[i]);
60-
shiftLeft(KR, 28, shiftTable[i]);
61-
Transform(SubKey[i], K, PC_2Table, 48);
60+
shiftLeft(KL, 28, shiftTable[i]); //左移
61+
shiftLeft(KR, 28, shiftTable[i]);
62+
Transform(SubKey[i], K, PC_2Table, 48); //据PC2表做转换
6263
}
6364
}
6465

Encryption/EncryptAlgorithm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ string getText(string filename);
1818
void writeCiphertext(string ciphertext, string fileName);
1919
int main()
2020
{
21-
string plaintext = "hello nsfjnoiwjwljelk";
2221
printHead();
2322
int a;
2423
while (cin>>a)
@@ -55,7 +54,7 @@ void printHead() {
5554
cout << "- 5.DSS签名算法 -" << endl;
5655
cout << "- 6.退出 -" << endl;
5756
cout << "---------------------------------------" << endl;
58-
cout << "明文内容为:Hello are you OK i am lei jun\n" << endl;
57+
cout << "明文内容为:"+ getText("plaintext.txt") +"\n" << endl;
5958
cout << "选择:";
6059
}
6160

Encryption/MD5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MD5
149149
dtemp = d + dtemp;
150150
}
151151

152-
//转换为16进制数 (实在没看懂)
152+
//转换为16进制数 (实在没看懂) 百科的代码
153153
string changeHex(int a) {
154154
int b;
155155
string str1;

Encryption/RSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RSA
7373
}
7474

7575
private:
76-
//三位素数
76+
//三位素数 从这里面取
7777
int prime[90] = { 401, 409, 419, 421, 431, 433, 439,
7878
443, 449, 457, 461, 463, 467, 479, 487, 491, 499,
7979
503, 509, 521, 523, 541, 547, 557, 563, 569, 571,

Encryption/Vigenere.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class Vigenere {
1313
secretKeyWord = keyword;
1414
initSecretKeyNum();
1515
}
16+
1617
string Encrypt(string plaintext) {
17-
//initSecretKeyNum(keyword);
18-
transform(plaintext.begin(), plaintext.end(), plaintext.begin(), tolower);
18+
transform(plaintext.begin(), plaintext.end(), plaintext.begin(), tolower); //È«²¿×ª»»ÎªÐ¡Ð´
1919
ciphertext = transPlainToCipher(plaintext);
2020
return ciphertext;
2121
}
2222

2323
string Decrypt(string ciphertext) {
24-
//initSecretKeyNum(keyword);
2524
plaintext = transCipherToPlain(ciphertext);
2625
return plaintext;
2726
}
2827

2928
private:
3029
string secretKeyWord = "china";
3130
int secretKeyNum[5];
31+
3232
//Get secretKeyNum
3333
void initSecretKeyNum() {
3434
for (unsigned int i = 0; i < secretKeyWord.size(); ++i)

Encryption/ciphertext.md5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
edd12a79ee29797ee0b539e90eae7c43
1+
4de6de7e42aa8d6f9b7d7e3864d1985b

0 commit comments

Comments
 (0)