-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitors.cpp
More file actions
152 lines (124 loc) · 3.52 KB
/
Copy pathmonitors.cpp
File metadata and controls
152 lines (124 loc) · 3.52 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "monitors.h"
// Plain text
// input: single plaintxt
// output: a string
string returnPlain(Plaintext pt) {
string res;
res = pt.to_string();
return res;
}
// input: vector of plaintxt
// output: vector of strings
vector<string> returnPlain(vector<Plaintext> pt) {
vector<string> res1D;
for (int i = 0; i < pt.size(); i++) {
res1D.emplace_back(returnPlain(pt[i]));
}
return res1D;
}
// input: 2D vector of plaintxt
// output: 2D vector of strings
vector<vector<string>> returnPlain(vector<vector<Plaintext>> pt) {
vector<vector<string>> res2D;
for (int i = 0; i < pt.size(); i++) {
res2D.emplace_back(returnPlain(pt[i]));
}
return res2D;
}
// save single plaintxt into a txt file
void savePlain(Plaintext pt, string file) {
string res;
res = returnPlain(pt);
// save to a text file
ofstream outputFile(file);
outputFile << res << endl;
}
// save vector of plaintxt
void savePlain(vector<Plaintext> pt, string file) {
vector<string> res1D;
res1D = returnPlain(pt);
// save to a text file
ofstream outputFile(file);
for (int row = 0; row < res1D.size(); row++) {
outputFile << "r" << row << endl;
outputFile << res1D[row] << endl;
}
}
// save 2d vector of plaintxt
void savePlain(vector<vector<Plaintext>> pt, string file) {
vector<vector<string>> res2D;
res2D = returnPlain(pt);
// save to a text file
ofstream outputFile(file);
for (int row = 0; row < res2D.size(); row++)
for (int col = 0; col < res2D[row].size(); col++) {
outputFile << "r" << row << "c" << col << endl;
outputFile << res2D[row][col] << endl;
}
}
// Cipher text
// input: single ciphertxt
// output: a vector of strings
vector<string> returnCipher(Ciphertext ct) {
vector<string> res;
BigPolyArray bpact(ct);
for (int i = 0; i < ct.size(); i++) {
string tmp = bpact[i].to_string();
res.emplace_back(tmp);
// cout << i << ": " << tmp << endl;
}
return res;
}
// input: vector of ciphertxt
// output: vector of vector of strings
vector<vector<string>> returnCipher(vector<Ciphertext> ct) {
vector<vector<string>> res1D;
for (int i = 0; i < ct.size(); i++) {
res1D.emplace_back(returnCipher(ct[i]));
}
return res1D;
}
// input: vector of ciphertxt
// output: vector of vector of strings
vector<vector<vector<string>>> returnCipher(vector<vector<Ciphertext>> ct) {
vector<vector<vector<string>>> res2D;
for (int i = 0; i < ct.size(); i++) {
res2D.emplace_back(returnCipher(ct[i]));
}
return res2D;
}
// save single ciphertxt
void saveCipher(Ciphertext ct, string file) {
vector<string> res;
res = returnCipher(ct);
// save to a text file
ofstream outputFile(file);
outputFile << "size: " << res.size() << endl;
for (const auto &row : res)
outputFile << row << endl;
}
// save vector of ciphertxt
void saveCipher(vector<Ciphertext> ct, string file) {
vector<vector<string>> res1D;
res1D = returnCipher(ct);
// save to a text file
ofstream outputFile(file);
for (int row = 0; row < res1D.size(); row++) {
outputFile << "r" << row << " Size: " << res1D[row].size() << endl;
for (const auto &col : res1D[row])
outputFile << col << endl;
}
}
// save 2d vector of ciphertxt
void saveCipher(vector<vector<Ciphertext>> ct, string file) {
vector<vector<vector<string>>> res2D;
res2D = returnCipher(ct);
// save to a text file
ofstream outputFile(file);
for (int row = 0; row < res2D.size(); row++)
for (int col = 0; col < res2D[row].size(); col++) {
outputFile << "r" << row << "c" << col << " Size: " << res2D[row][col].size() << endl;
for (const auto &col : res2D[row][col])
outputFile << col << endl;
}
}