MCPcopy Create free account
hub / github.com/Huelse/SEAL-Python / ckks_encoder_example

Function ckks_encoder_example

examples/2_encoders.py:43–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41
42
43def 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
72if __name__ == "__main__":

Callers 1

2_encoders.pyFile · 0.85

Calls 2

print_example_bannerFunction · 0.90
print_vectorFunction · 0.90

Tested by

no test coverage detected