()
| 41 | |
| 42 | |
| 43 | def ckks_encoder_example(): |
| 44 | print_example_banner("Example: Encoders / CKKS") |
| 45 | |
| 46 | parms = EncryptionParameters(scheme_type.ckks) |
| 47 | poly_modulus_degree = 8192 |
| 48 | parms.set_poly_modulus_degree(poly_modulus_degree) |
| 49 | parms.set_coeff_modulus(CoeffModulus.Create(poly_modulus_degree, [40, 40, 40, 40, 40])) |
| 50 | context = SEALContext(parms) |
| 51 | |
| 52 | encoder = CKKSEncoder(context) |
| 53 | keygen = KeyGenerator(context) |
| 54 | encryptor = Encryptor(context, keygen.create_public_key()) |
| 55 | evaluator = Evaluator(context) |
| 56 | decryptor = Decryptor(context, keygen.secret_key()) |
| 57 | relin_keys = keygen.create_relin_keys() |
| 58 | |
| 59 | input_vec = [0.0, 1.1, 2.2, 3.3] |
| 60 | scale = 2.0 ** 30 |
| 61 | plain = encoder.encode(input_vec, scale) |
| 62 | encrypted = encryptor.encrypt(plain) |
| 63 | |
| 64 | evaluator.square_inplace(encrypted) |
| 65 | evaluator.relinearize_inplace(encrypted, relin_keys) |
| 66 | |
| 67 | output_plain = decryptor.decrypt(encrypted) |
| 68 | output = encoder.decode(output_plain) |
| 69 | print_vector(output, 4, 4) |
| 70 | |
| 71 | |
| 72 | if __name__ == "__main__": |
no test coverage detected