-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (73 loc) · 1.98 KB
/
main.cpp
File metadata and controls
80 lines (73 loc) · 1.98 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include "PassWord.h"
#include "Process.h"
using namespace std;
//This is a test sentence
int main()
{
string inputName;
string outputName;
int pattern;
char passWord[8];
char plaintext[8];
char chipertext[8];
cout << "Please enter the input file name" << endl;
cin >> inputName;
cout << "Please enter the output file name" << endl;
cin >> outputName;
cout << "Please enter operation type 1. Encryption 2. Decryption" << endl;
cin >> pattern;
cout << "Please enter the password" << endl;
for(int i = 0; i < 8; ++i) {
cin >> passWord[i];
}
PassWord passWordSet(passWord);
if(pattern == 2) { ///If you want to perform decryption, simply reverse the password
passWordSet.reversePwdSet();
}
ifstream cin1(inputName);
ofstream cout1(outputName);
Process process; ///Read in without filtering whitespace or enter
int counter;
for(counter = 1; cin1 >> noskipws >> plaintext[counter - 1];) {
if(counter == 8) {
process.encryption(plaintext, chipertext, passWordSet);
for(int i = 0; i < 8; ++i) {
cout1 << chipertext[i];
}
counter = 1;
} else {
counter++;
}
}
if(pattern == 1 && counter != 1) {
for(int i = counter - 1; i < 8; ++i) {
plaintext[i] = ' ';
}
process.encryption(plaintext, chipertext, passWordSet);
for(int i = 0; i < 8; ++i) {
cout1 << chipertext[i];
}
}
cin1.close();
cout1.close();
return 0;
}
/*
This is the bit operation in C++
set i as 1: c |= (1 << i);
set i as 0: c &= ~(1<<i);
return the value: return (c >> i) & 1;
set the reserve value: c ^= (1 << i);
This is a example for input
plaintext.txt
chipertext.txt
1
qwer1234
chipertext.txt
plaintext2.txt
2
qwer1234
*/