@@ -95,24 +95,32 @@ Another example of how the library can be used with shortints:
95
95
use tfhe :: shortint :: prelude :: * ;
96
96
97
97
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:
99
99
let (client_key , server_key ) = gen_keys (Parameters :: default ());
100
100
101
- let msg1 = 1 ;
102
- let msg2 = 0 ;
101
+ let msg1 = 3 ;
102
+ let msg2 = 2 ;
103
103
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:
107
105
let ct_1 = client_key . encrypt (msg1 );
108
106
let ct_2 = client_key . encrypt (msg2 );
109
107
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 );
112
120
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 ));
116
124
}
117
125
```
118
126
0 commit comments