- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我对密文和最后的正方形进行了一系列计算。问题是,即使有足够的噪声预算来执行平方和重新线性化(在操作之前和之后),当我解密它时,我也会得到不正确的结果。
奇怪的是,如果我解密和解码,然后在新的密文中再次编码和加密,在平方之前的数字,计算是正确执行的。
我不明白问题出在哪里,因为如果设置的参数有误,无论如何我都会得到不正确的结果。
我指定我使用分数编码器,整数部分的多项式系数为 64,小数部分的精度为 32 位(基数为 3),并且我在平方前的所有计算都在密文和明文之间执行。
这是我的意思的一个例子:
#include <vector>
#include "seal/seal.h"
using namespace std;
using namespace seal;
int main(int argc, char const *argv[])
{
//Set parameters
EncryptionParameters parms;
parms.set_poly_modulus("1x^4096 + 1");
parms.set_coeff_modulus(coeff_modulus_128(4096));
parms.set_plain_modulus(1<<20);
SEALContext context(parms);
KeyGenerator keygen(context);
PublicKey public_key = keygen.public_key();
SecretKey secret_key = keygen.secret_key();
EvaluationKeys ev_keys16;
keygen.generate_evaluation_keys(16, ev_keys16);
Encryptor encryptor(context, public_key);
Evaluator evaluator(context);
Decryptor decryptor(context, secret_key);
FractionalEncoder fraencoder(context.plain_modulus(), context.poly_modulus(), 64, 32, 3);
float data=0.5;
float weight= 1.5;
//encrypt data and encode weight
Ciphertext encrypted_data;
encryptor.encrypt(fraencoder.encode(data),encrypted_data);
cout<<"Noise budget in a freshly encrypted: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
Plaintext encoded_weight=fraencoder.encode(weight);
//Operation: (0.5*1.5)*5=3.75
vector<Ciphertext> mul_vector(5);
for(int i=0;i<5;i++){
evaluator.multiply_plain(encrypted_data,encoded_weight,mul_vector[i]);
}
evaluator.add_many(mul_vector,encrypted_data);
cout<<"Noise budget after 5 plain multiplications and 4 additions: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
//Operation: 3.75*4=15
vector<Ciphertext> add_vector(4);
for(int i=0;i<4;i++){
add_vector[i]= Ciphertext(encrypted_data);
}
evaluator.add_many(add_vector,encrypted_data);
cout<<"Noise budget after 4 additions: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
//Operation: (15-1.5)*1.5=20.25
evaluator.sub_plain(encrypted_data,encoded_weight);
evaluator.multiply_plain(encrypted_data,encoded_weight);
cout<<"Noise budget after 1 plain sub and 1 plain multiplication: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
//Operation: (20.25*1.5)*6=182.25
vector<Ciphertext> mul_vector2(6);
for(int i=0;i<6;i++){
evaluator.multiply_plain(encrypted_data,encoded_weight,mul_vector2[i]);
}
evaluator.add_many(mul_vector2,encrypted_data);
cout<<"Noise budget after 6 plain multiplications and 5 additions: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
// here I decrypt, decode and encrypt again, to obtain the right result
Plaintext tmp;
float res;
//If I remove the following 4 lines the final result is incorrect
decryptor.decrypt(encrypted_data,tmp);
res = fraencoder.decode(tmp);
cout<<"Decrypted result before square: "<<res<<endl;
encryptor.encrypt(fraencoder.encode(res),encrypted_data);
//182.25^2=33215.1
evaluator.square(encrypted_data);
evaluator.relinearize(encrypted_data,ev_keys16);
cout<<"Noise budget after square and relianearization: "<<decryptor.invariant_noise_budget(encrypted_data)<<endl;
decryptor.decrypt(encrypted_data,tmp);
res= fraencoder.decode(tmp);
cout<<res<<endl;
return 0;
}
我错过了什么?
最佳答案
问题是你的 plain_modulus
对于这个计算来说太小了。
如果你打印出tmp
最后(tmp.to_string()
)你会看到它有非常大的系数。请注意,这些系数是模 plain_modulus
所以他们中的许多人预计看起来很大。尽管如此,res
的无穷范数作为一个整数(即,如果您使用足够大的 plain_modulus
)是 266441508,刚好低于 229。由于您的 plain_modulus
只有 220,你最终会得到不正确的结果。您的重新编码有所帮助,因为在最后一次计算之前,系数仍然不太大,并且重新编码多项式会将系数降低回无穷范数 1(在您的情况下,基数 = 3)。
解决方法是增加plain_modulus
到至少 229。当然,这会导致更多的噪音增长,并且您已经非常接近噪音溢出,但它仍然有效。
关于c++ - SEAL:平方运算后解密不正确,即使密文的噪声预算大于零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52059476/
为什么 (defun boolimplies (a b) (or (not a) b)) if called as(boolimplies 'a 'b) 返回 B? 即使我不使用任何 boolean
这个问题已经有答案了: Are there builtin functions for elementwise boolean operators over boolean lists? (5 个回答
我正在寻求帮助以使以下功能看起来更清晰。我觉得我可以通过使用更少的代码行来实现同样的目标。 标题看起来一定很困惑,所以让我详细说明一下。我创建了一个函数,它接受用户输入(即 72+5),将字符串拆分为
我正在学习 C++ 并尝试为矩阵编写一个 C++ 类,我在其中将矩阵存储为一维 C 数组。为此,我定义了一个 element成员函数根据矩阵元素在数组中的位置访问矩阵元素。然后我重载了 class
我正在学习 C++ 并尝试为矩阵编写一个 C++ 类,我在其中将矩阵存储为一维 C 数组。为此,我定义了一个 element成员函数根据矩阵元素在数组中的位置访问矩阵元素。然后我重载了 class
伙计们,以下内容不起作用 函数返回 true,变量返回 false,但它不会进入 when 子句。我尝试像这样放大括号 但是当我将变量的值设置为 true 并将上面的代码更改为 它进入w
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我是原生 C 语言的新手,但我没有看到错误。 我尝试在这种情况下使用 if 操作: #define PAGE_A 0 #define PAGE_B 1 int pageID = 0; if (page
我正在从事一个项目,让用户鼠标滚轮移动并知道它向上或向下滚动。在我的代码中,我可以上下移动。但我想将 Action 保存到一个字符串中。例如,如果用户向上向上向下滚动'mhmh' 显示返回“UUD”但
我有一个 MySQL 表 payment我在其中存储客户的所有付款相关数据。表字段为:fileNo , clientName , billNo , billAmount , status 。我想构建一
我的表架构如下: +------+-------+-------+
我有这个(顺便说一句,我刚刚开始学习): #include #include using namespace std; int main() { string mystr; cout << "We
我正在用 bash 构建一个用于 Linux (SLES 11SP3) 的脚本。我想通过使用以下语法查找它的 pid 来检查某个进程是否存在: pid="$(ps -ef | grep -v grep
我有一个包含两列的表格; CREATE TABLE IF NOT EXISTS `QUESTION_CATEGORY_RELATION` ( `question_id` int(16) NOT N
我对 Python 如何计算 bool 语句感到困惑。 例如 False and 2 or 3 返回 3 这是如何评估的?我认为 Python 首先会查看“False and 2”,甚至不查看“or
这个问题在这里已经有了答案: 12 年前关闭。 这可能是非常基本的......但我似乎不明白: 如何 (2 & 1) = 0 (3 & 1) = 1 (4 & 1) = 0 等等.. 上面的这种模式似
无论如何在Haskell中定义如下函数? or True True = True or True undefined = True or True False
如您所知,TCL 有一些数学函数,例如 罪 , 因 , 和 假设 在 中调用的expr 带有 的命令() 大括号如下: puts [expr sin(1.57)] 现在如何使用 TCL 添加功能 li
让我们考虑两个数组列表。 ArrayList list1 = new ArrayList(); list1.add(1); list1.add(2); list1.add(3); ArrayList
我想包含和排除使用AND和OR的专业知识,包括与AND和OR操作正常工作。但是,当将排除专家与AND和OR一起使用时,返回与3相同的结果计数。我使用的是1.4版 Elasticsearch 。帮助我解
我是一名优秀的程序员,十分优秀!