SchemeLWE::not_gate implemented

This commit is contained in:
hilder.vitor
2022-03-11 12:45:03 +01:00
parent d9c77a45a7
commit 60c01e16d8
2 changed files with 17 additions and 0 deletions

View File

@ -151,6 +151,14 @@ class SchemeLWE
* @param[in] ct_2 encryption of the second input bit
*/
void xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) const;
/**
* Computes the NOT gate of a given ciphertext ct
* @param[out] ct_res encryption of the outuput of the NOT gate
* @param[in] ct encryption of the input bit
*/
void not_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct) const;
};

View File

@ -484,4 +484,13 @@ void SchemeLWE::xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE&
bootstrap(ct_res);
}
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);
}