Skip to content

Commit f72fcb0

Browse files
committed
chore(tfhe): update README
1 parent 941fa09 commit f72fcb0

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,32 @@ Another example of how the library can be used with shortints:
9595
use tfhe::shortint::prelude::*;
9696

9797
fn main() {
98-
// We generate a set of client/server keys, using the default parameters:
98+
// Generate a set of client/server keys, using the default parameters:
9999
let (client_key, server_key) = gen_keys(Parameters::default());
100100

101-
let msg1 = 1;
102-
let msg2 = 0;
101+
let msg1 = 3;
102+
let msg2 = 2;
103103

104-
let modulus = client_key.parameters.message_modulus.0;
105-
106-
// We use the client key to encrypt two messages:
104+
// Encrypt two messages using the (private) client key:
107105
let ct_1 = client_key.encrypt(msg1);
108106
let ct_2 = client_key.encrypt(msg2);
109107

110-
// We use the server public key to execute an integer circuit:
111-
let ct_3 = server_key.unchecked_add(&ct_1, &ct_2);
108+
// Homomorphically compute an addition
109+
let ct_add = server_key.unchecked_add(&ct_1, &ct_2);
110+
111+
// Define the Hamming weight function
112+
// f: x -> sum of the bits of x
113+
let f = |x:u64| x.count_ones() as u64;
114+
115+
// Generate the accumulator for the function
116+
let acc = server_key.generate_accumulator(f);
117+
118+
// Compute the function over the ciphertext using the PBS
119+
let ct_res = server_key.keyswitch_programmable_bootstrap(&ct_add, &acc);
112120

113-
// We use the client key to decrypt the output of the circuit:
114-
let output = client_key.decrypt(&ct_3);
115-
assert_eq!(output, (msg1 + msg2) % modulus as u64);
121+
// Decrypt the ciphertext using the (private) client key
122+
let output = client_key.decrypt(&ct_res);
123+
assert_eq!(output, f(msg1 + msg2));
116124
}
117125
```
118126

0 commit comments

Comments
 (0)