-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundled_CTR_test2.cpp
97 lines (81 loc) · 2.22 KB
/
bundled_CTR_test2.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
#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};
//bundled_CTR Mode(key, nonce);
string fileContent;
string new_data;
int num = 0;
cout << "What size (*10): ";
cin >> num;
int size = (num)*10;
bundled_CTR Mode(key, nonce);
ifstream inputFile("204800.txt");
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;
}
new_data = fileContent.substr(0, size);
ofstream timeStamp("Del_" + to_string(size) + "_bundled_CTR.txt", ios::app);
if(timeStamp.is_open())
{
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, 102400);
end_time = chrono::high_resolution_clock::now();
}
else if(i%3 == 1)
{
start_time = chrono::high_resolution_clock::now();
Mode.Deletion(size, 102400);
end_time = chrono::high_resolution_clock::now();
}
else if(i%3 == 2)
{
start_time = chrono::high_resolution_clock::now();
Mode.Replacement(new_data, 102400);
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;
}