()
| 4 | |
| 5 | |
| 6 | def bfv_batch_encoder_example(): |
| 7 | print_example_banner("Example: Encoders / BFV Batching") |
| 8 | |
| 9 | parms = EncryptionParameters(scheme_type.bfv) |
| 10 | poly_modulus_degree = 8192 |
| 11 | parms.set_poly_modulus_degree(poly_modulus_degree) |
| 12 | parms.set_coeff_modulus(CoeffModulus.BFVDefault(poly_modulus_degree)) |
| 13 | parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20)) |
| 14 | |
| 15 | context = SEALContext(parms) |
| 16 | print_parameters(context) |
| 17 | |
| 18 | keygen = KeyGenerator(context) |
| 19 | encryptor = Encryptor(context, keygen.create_public_key()) |
| 20 | evaluator = Evaluator(context) |
| 21 | decryptor = Decryptor(context, keygen.secret_key()) |
| 22 | batch_encoder = BatchEncoder(context) |
| 23 | |
| 24 | slot_count = batch_encoder.slot_count() |
| 25 | pod_matrix = [0] * slot_count |
| 26 | pod_matrix[0:8] = [0, 1, 2, 3, 4, 5, 6, 7] |
| 27 | |
| 28 | plain_matrix = batch_encoder.encode(pod_matrix) |
| 29 | encrypted_matrix = encryptor.encrypt(plain_matrix) |
| 30 | |
| 31 | pod_matrix2 = [((i & 1) + 1) for i in range(slot_count)] |
| 32 | plain_matrix2 = batch_encoder.encode(pod_matrix2) |
| 33 | |
| 34 | encrypted_matrix = evaluator.add_plain(encrypted_matrix, plain_matrix2) |
| 35 | evaluator.square_inplace(encrypted_matrix) |
| 36 | evaluator.relinearize_inplace(encrypted_matrix, keygen.create_relin_keys()) |
| 37 | |
| 38 | plain_result = decryptor.decrypt(encrypted_matrix) |
| 39 | pod_result = batch_encoder.decode(plain_result) |
| 40 | print_vector(pod_result.astype(np.float64), 8, 0) |
| 41 | |
| 42 | |
| 43 | def ckks_encoder_example(): |
no test coverage detected