mirror of
https://github.com/mii443/FINAL.git
synced 2025-08-22 15:05:36 +00:00
Update README with XOR and NOT
This commit is contained in:
17
README.md
17
README.md
@ -21,7 +21,7 @@ A C++ compiler, the [NTL](https://libntl.org) and [FFTW 3](http://www.fftw.org)
|
||||
|
||||
Use `test.cpp` and `Makefile` as reference points to create and compile your own program with FINAL.
|
||||
|
||||
### Example: XOR
|
||||
### Example
|
||||
```c++
|
||||
// Input bits
|
||||
int b1 = 0;
|
||||
@ -30,15 +30,24 @@ int b2 = 1;
|
||||
// LWE encryption base scheme
|
||||
SchemeLWE s;
|
||||
// LWE ciphertexts
|
||||
Ctxt_LWE ct1, ct2, ct_or, ct_nand, ct_xor;
|
||||
Ctxt_LWE ct1, ct2, ct_or, ct_nand, ct_xor, ct_and, ct_not;
|
||||
// Encryption of bits
|
||||
s.encrypt(ct1, b1);
|
||||
s.encrypt(ct2, b2);
|
||||
|
||||
// Computes AND
|
||||
s.and_gate(ct_and, ct1, ct2);
|
||||
assert(s.decrypt(ct_and) == 0);
|
||||
// Computes NAND
|
||||
s.nand_gate(ct_nand, ct1, ct2);
|
||||
assert(s.decrypt(ct_nand) == 1);
|
||||
// Computes OR
|
||||
s.or_gate(ct_or, ct1, ct2);
|
||||
// Combines the previous results with AND to get XOR
|
||||
s.and_gate(ct_xor, ct_nand, ct_or);
|
||||
assert(s.decrypt(ct_or) == 1);
|
||||
// Computes XOR
|
||||
s.xor_gate(ct_xor, ct1, ct2);
|
||||
assert(s.decrypt(ct_xor) == 1);
|
||||
// Computes NOT
|
||||
s.not_gate(ct_not, ct1);
|
||||
assert(s.decrypt(ct_not) == 1);
|
||||
```
|
||||
|
Reference in New Issue
Block a user