-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundled_CTR_test1.cpp
102 lines (85 loc) · 2.39 KB
/
bundled_CTR_test1.cpp
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
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include <chrono>
#include "crypto.h"
int main()
{
srand(time(NULL));
byte nonce[AES::BLOCKSIZE/2];
for (int i = 0; i < AES::BLOCKSIZE/2; i++)
{
nonce[i] = (byte)rand()%256;
}
byte counter[AES::BLOCKSIZE/2] = {0x00, };
byte key[AES::DEFAULT_KEYLENGTH] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10};
int n = 100;
string fileContent;
string f_name = "";
string new_data = " He has kept among us, in times of peace, Standing Armies without the Consent of our legislatures. ";
int num = 0;
cout << "What size (KB): ";
cin >> num;
int size = (num)*1024;
f_name = to_string(size);
f_name += ".txt";
string mode = "bundled_CTR";
bundled_CTR Mode(key, nonce);
ifstream inputFile(f_name);
if (inputFile.is_open()) {
inputFile.seekg(0, ios::end);
streampos fileSize = inputFile.tellg();
inputFile.seekg(0, ios::beg);
fileContent.resize(fileSize);
inputFile.read(&fileContent[0], fileSize);
inputFile.close();
}
else {
cerr << "Cannot open file" << endl;
return 1;
}
ofstream timeStamp(mode + "_" + to_string(size) + ".txt", ios::app);
if(timeStamp.is_open())
{
//timeStamp << "file size is " << size << endl;
Mode.Insertion(fileContent, 0);
auto start_time = chrono::high_resolution_clock::now();
auto end_time = chrono::high_resolution_clock::now();
int i = rand()%256;
if(i%3 == 0)
{
start_time = chrono::high_resolution_clock::now();
Mode.Insertion(new_data, size/2);
end_time = chrono::high_resolution_clock::now();
}
else if(i%3 == 1)
{
start_time = chrono::high_resolution_clock::now();
Mode.Deletion(100, size/2);
end_time = chrono::high_resolution_clock::now();
}
else if(i%3 == 2)
{
start_time = chrono::high_resolution_clock::now();
Mode.Replacement(new_data, size/2);
end_time = chrono::high_resolution_clock::now();
}
auto duration = chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
timeStamp << duration.count() <<endl;
timeStamp.close();
//vector<byte> re_plain = decryption(nonce, Mode.print_data(), key, Mode.print_meta());
/*cout << "Data size: " << size << " Decrypted data: ";
for(auto loop: re_plain)
{
cout << loop;
}
cout << endl;*/
}
else {
cerr << "Cannot open file" << endl;
return 1;
}
return 0;
}