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

Function levels_example

examples/3_levels.py:5–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4
5def levels_example():
6 print_example_banner("Example: Levels")
7
8 parms = EncryptionParameters(scheme_type.bfv)
9 poly_modulus_degree = 8192
10 parms.set_poly_modulus_degree(poly_modulus_degree)
11 parms.set_coeff_modulus(CoeffModulus.Create(poly_modulus_degree, [50, 30, 30, 50, 50]))
12 parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20))
13
14 context = SEALContext(parms)
15 print_parameters(context)
16
17 context_data = context.key_context_data()
18 print("modulus switching chain:")
19 while context_data is not None:
20 print(f" chain index: {context_data.chain_index()}, coeff modulus count: {len(context_data.parms().coeff_modulus())}")
21 context_data = context_data.next_context_data()
22
23 keygen = KeyGenerator(context)
24 encryptor = Encryptor(context, keygen.create_public_key())
25 evaluator = Evaluator(context)
26 decryptor = Decryptor(context, keygen.secret_key())
27
28 plain = Plaintext("1x^3 + 2x^2 + 3x^1 + 4")
29 encrypted = encryptor.encrypt(plain)
30
31 print("noise budget while switching levels:")
32 while True:
33 print(f" {decryptor.invariant_noise_budget(encrypted)} bits")
34 try:
35 evaluator.mod_switch_to_next_inplace(encrypted)
36 except ValueError:
37 break
38
39 decrypted = decryptor.decrypt(encrypted)
40 print("decrypted after switching:", decrypted.to_string())
41
42
43if __name__ == "__main__":

Callers 1

3_levels.pyFile · 0.85

Calls 2

print_example_bannerFunction · 0.90
print_parametersFunction · 0.90

Tested by

no test coverage detected