Closed Zeng1998 closed 4 years ago
for(int i=1;i<=M;i++){
Ciphertext c_sum=zero_cr;
for(int j=1;j<=M;j++){
string name="/home/keane/CLionProjects/sim/sim_"+to_string(i)+"_"+to_string(j)+".data";
read_by_file(name,cr,context);
evaluator.multiply_inplace(cr,user[j]);
evaluator.add_inplace(c_sum,cr);
decryptor.decrypt(c_sum,pr);
}
decryptor.decrypt(c_sum,pr);
auto val=encoder.decode_uint64(pr);
cout << i << val << endl;
}
This is wrong
for(int i=1;i<=M;i++){
Ciphertext c_sum=zero_cr;
for(int j=1;j<=M;j++){
int vv=666;
encryptor.encrypt(encoder.encode(vv),cr);
evaluator.multiply_inplace(cr,cr);
evaluator.add_inplace(c_sum,cr);
decryptor.decrypt(c_sum,pr);
}
decryptor.decrypt(c_sum,pr);
auto val=encoder.decode_uint64(pr);
cout << i << val << endl;
}
And this is right
I want to calculate the dot product of a vector, but find that the sum overflow becomes negative during the calculation. The maximum value is about 20,000. But when I took this part alone for testing, I used the same method to multiply and accumulate random numbers, and found that it would not overflow, and the addition of the int ciphertext was normal. I lack the theoretical basis of homomorphic encryption, and I want to know if I need to set certain parameters or call certain methods.