MCPcopy Create free account
hub / github.com/OpenMined/TenSEAL / test_ckks_encoder

Function test_ckks_encoder

tests/python/sealapi/test_encode_decode.py:23–51  ·  view source on GitHub ↗
(testcase)

Source from the content-addressed store, hash-verified

21
22@pytest.mark.parametrize("testcase", [[10, 20, 30], [1 / div for div in range(2, 10)]])
23def test_ckks_encoder(testcase):
24 ctx = helper_context_ckks()
25 encoder = sealapi.CKKSEncoder(ctx)
26
27 plaintext = sealapi.Plaintext()
28 encoder.encode(testcase, 2**40, plaintext)
29 out = encoder.decode_double(plaintext)
30
31 is_close_enough(out, testcase)
32
33 keygen = sealapi.KeyGenerator(ctx)
34 pk = sealapi.PublicKey()
35 public_key = keygen.create_public_key(pk)
36 secret_key = keygen.secret_key()
37
38 decryptor = sealapi.Decryptor(ctx, secret_key)
39 encryptor = sealapi.Encryptor(ctx, pk, secret_key)
40
41 plaintext = sealapi.Plaintext()
42 ciphertext = sealapi.Ciphertext(ctx)
43
44 encoder.encode(testcase, 2**40, plaintext)
45 encryptor.encrypt(plaintext, ciphertext)
46
47 plaintext_out = sealapi.Plaintext()
48
49 decryptor.decrypt(ciphertext, plaintext_out)
50 decrypted = encoder.decode_double(plaintext)
51 is_close_enough(decrypted, testcase)

Callers

nothing calls this directly

Calls 6

helper_context_ckksFunction · 0.85
is_close_enoughFunction · 0.85
encodeMethod · 0.45
secret_keyMethod · 0.45
encryptMethod · 0.45
decryptMethod · 0.45

Tested by

no test coverage detected