diff --git a/include/lwehe.h b/include/lwehe.h index abb7d6e..c4d6f6f 100644 --- a/include/lwehe.h +++ b/include/lwehe.h @@ -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; }; diff --git a/src/lwehe.cpp b/src/lwehe.cpp index 025b716..d9b04a2 100644 --- a/src/lwehe.cpp +++ b/src/lwehe.cpp @@ -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(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); +}