Created
September 30, 2021 11:32
-
-
Save randhindi/089cd67b93016890ad7455cc74ba808d to your computer and use it in GitHub Desktop.
Concrete Boolean example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate concrete_boolean; | |
use concrete_boolean::gen_keys; | |
// We generate a set of client/server keys, using the default parameters: | |
let (client_key, server_key) = gen_keys(); | |
// We use the client secret key to encrypt two messages: | |
let ct_1 = client_key.encrypt(true); | |
let ct_2 = client_key.encrypt(false); | |
// We use the server public key to execute a boolean circuit: | |
// if ((NOT ct_2) NAND (ct_1 AND ct_2)) then (NOT ct_2) else (ct_1 AND ct_2) | |
let ct_3 = server_key.not(&ct_2); | |
let ct_4 = server_key.and(&ct_1, &ct_2); | |
let ct_5 = server_key.nand(&ct_3, &ct_4); | |
let ct_6 = server_key.mux(&ct_5, &ct_3, &ct_4); | |
// We use the client key to decrypt the output of the circuit: | |
let output = client_key.decrypt(&ct_6); | |
assert_eq!(output, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment