mirror of
https://github.com/mii443/FINAL.git
synced 2025-08-22 15:05:36 +00:00
LWE scheme: homomorphic XOR gate implemented
This commit is contained in:
@ -143,10 +143,18 @@ class SchemeLWE
|
||||
* @param[in] ct_2 encryption of the second input bit
|
||||
*/
|
||||
void or_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) const;
|
||||
|
||||
/**
|
||||
* Computes the XOR gate of two given ciphertexts ct1 and ct2
|
||||
* @param[out] ct_res encryptions of the outuput of the NAND gate
|
||||
* @param[in] ct_1 encryption of the first input bit
|
||||
* @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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -470,4 +470,18 @@ void SchemeLWE::or_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& c
|
||||
ct_res = parLWE.or_const - (ct1 + ct2);
|
||||
bootstrap(ct_res);
|
||||
//cout << "OR: " << float(clock()-start)/CLOCKS_PER_SEC << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SchemeLWE::xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) 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] = 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)
|
||||
bootstrap(ct_res);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user