minor changes to simplify code of xor and not gates

This commit is contained in:
hilder.vitor
2022-03-24 22:07:27 +01:00
parent b554fbbe54
commit b9ef82bb9a
2 changed files with 8 additions and 11 deletions

View File

@ -477,10 +477,10 @@ void SchemeLWE::xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE&
{
if (ct_res.a.size() != parLWE.n)
ct_res.a = vector<int>(parLWE.n);
for (size_t i = 0; i < parLWE.n; i++)
ct_res.a[i] = parLWE.mod_q_base(2*(ct1.a[i] + ct2.a[i])); // a = 2*(ct1.a + ct2.a)
ct_res.b = parLWE.mod_q_base(2*(ct1.b + ct2.b)); // b = 2*(ct1.b + ct2.b)
ct_res = ct1 + ct2;
ct_res = ct_res + ct_res; // ct = 2*(ct1 + ct2)
bootstrap(ct_res);
}
@ -488,9 +488,7 @@ void SchemeLWE::not_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct) const
{
if (ct_res.a.size() != parLWE.n)
ct_res.a = vector<int>(parLWE.n);
for (size_t i = 0; i < parLWE.n; i++)
ct_res.a[i] = -ct.a[i];
ct_res.b = parLWE.delta_base - ct.b;
ct_res.b = parLWE.mod_q_base(ct_res.b);
ct_res = parLWE.delta_base - ct;
}

View File

@ -288,10 +288,9 @@ void SchemeNTRU::xor_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NT
{
if (ct_res.data.size() != parNTRU.n)
ct_res.data = vector<int>(parNTRU.n);
for (size_t i = 0; i < parNTRU.n; i++){
ct_res.data[i] = 2*(ct1.data[i] + ct2.data[i]);
ct_res.data[i] = parNTRU.mod_q_base(ct_res.data[i]); // res = 2*(ct1 + ct2) % q
}
ct_res = ct1 + ct2;
ct_res = ct_res + ct_res; // ct_res = 2*(ct1 + ct2) % q
bootstrap(ct_res);
}