We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bgv方案计算密文乘法出现错误,计算密文状态下的0*1,结果为28733。代码如下:
#include "fhe/bgv/bgv.h" #include <iostream> #include <fstream> #include <vector> #include <cmath> #include <bitset> using namespace hehub; int main() { // 设置BGV加密环境 std::vector<u64> ct_moduli{131530753, 130809857}; // 示例模数 size_t dimension = 1; RnsPolyParams ct_params{dimension, ct_moduli.size(), ct_moduli}; RlweSk sk(ct_params); u64 pt_modulus = 65537; // 示例明文模数 RnsPolyParams pt_params{dimension, 1, std::vector{pt_modulus}}; // 生成重线性化密钥 u64 additional_mod = 131923969; // 额外模数 auto relin_key = get_relin_key(sk, additional_mod); auto data_count = dimension; std::vector<u64> plain_data1(data_count); std::vector<u64> plain_data2(data_count); u64 seed = 1; for (auto &d : plain_data1) { d = (seed++) % 2; } for (auto &d : plain_data2) { d = (seed++) % 2; } for (int i = 0; i < dimension; i++) { std::cout<<"plain_data1:"<<plain_data1[i]<<" "; } std::cout<<std::endl; for (int i = 0; i < dimension; i++) { std::cout<<"plain_data2:"<<plain_data2[i]<<" "; } std::cout<<std::endl; // encode auto pt1 = bgv::simd_encode(plain_data1, pt_modulus); auto pt2 = bgv::simd_encode(plain_data2, pt_modulus); // encrypt & arith auto ct1 = bgv::encrypt(pt1, sk); auto ct2 = bgv::encrypt(pt2, sk); auto ct_prod_quadratic = bgv::mult_low_level(ct1, ct2); auto ct_prod = bgv::relinearize(ct_prod_quadratic, relin_key); // decrypt auto prod_decrypted = bgv::decrypt(ct_prod, sk); auto prod_data = bgv::simd_decode(prod_decrypted); // check for (size_t i = 0; i < data_count; i++) { std::cout<<"prod_data"<<i+1<<":"<<prod_data[i]<<std::endl; } return 0; }
下面是运行结果:
plain_data1:1 plain_data2:0 prod_data1:28733
因为我需要在同态加密的情况下计算乘法和加法,所以我选择了bgv加密方案。我不清楚是不是我的代码有问题。感谢!
The text was updated successfully, but these errors were encountered:
我检查一下
Sorry, something went wrong.
No branches or pull requests
bgv方案计算密文乘法出现错误,计算密文状态下的0*1,结果为28733。代码如下:
下面是运行结果:
因为我需要在同态加密的情况下计算乘法和加法,所以我选择了bgv加密方案。我不清楚是不是我的代码有问题。感谢!
The text was updated successfully, but these errors were encountered: