-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypter.cpp
67 lines (49 loc) · 1.6 KB
/
decrypter.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
/*Author : Tuan Cau Rao*/
#include "./common_function.h"
int main(){
long iter,iter1;
fstream secretFile("secF_encrypter.txt",fstream::in);
unsigned long m,p,r;
vector<long> gens,orgs;
readContextBase(secretFile,m,p,r,gens,orgs);
FHEcontext context(m,p,r,gens,orgs);
secretFile >> context;
FHESecKey secretKey(context);
const FHEPubKey& publicKey = secretKey;
secretFile >> secretKey;
EncryptedArray ea(context);
long nslots = ea.size();
/*---------- DOC FILE result ------------------------*/
fstream resultFile("result.txt",fstream::in);
vector<Ctxt> vecCipher;
std::string line;
long nCipher;
resultFile >> nCipher;
cout << "Number of Ciphertext " << nCipher << endl;
for(iter = 0 ; iter < nCipher ; iter++){
cout << "read cipher " << iter << endl;
Ctxt nC(publicKey);
resultFile >> nC;
vecCipher.push_back(nC);
}
/*
while (std::getline(resultFile, line))
{
cout << "read cipher : " << nCipher << endl;
std::istringstream iss(line);
Ctxt a(publicKey);
if (!(iss >> a)) { break; } // error
nCipher++;
vecCipher.push_back(a);
// process pair (a,b)
}*/
resultFile.close();
/*------------------DECRYPTING PROCESS----------------*/
fstream decryptFile("decryptF.txt",fstream::out|fstream::trunc);
for(iter = 0; iter < nCipher ; iter++){
vector<long> vVal;
ea.decrypt(vecCipher[iter],secretKey,vVal);
decryptFile << convertToL(vVal,nslots) << endl;
}
decryptFile.close();
}