Rener Oliveira (Ubuntu WSL) 2 лет назад
Родитель
Сommit
9d50bfe846

+ 8 - 8
src/pke/examples/function-evaluation.py

@@ -27,19 +27,19 @@ def eval_logistic_example():
     cc.Enable(PKESchemeFeature.LEVELEDSHE)
     cc.Enable(PKESchemeFeature.ADVANCEDSHE)
 
-    keyPair = cc.KeyGen()
-    cc.EvalMultKeyGen(keyPair.secretKey)
+    key_pair = cc.KeyGen()
+    cc.EvalMultKeyGen(key_pair.secretKey)
 
     input = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
     encoded_length = len(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
-    ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
+    ciphertext = cc.Encrypt(key_pair.publicKey, plaintext)
 
     lower_bound = -4
     upper_bound = 4
     result = cc.EvalLogistic(ciphertext, lower_bound, upper_bound, poly_degree)
 
-    plaitext_dec = Decrypt(result, keyPair.secretKey)
+    plaitext_dec = Decrypt(result, key_pair.secretKey)
     plaitext_dec.SetLength(encoded_length)
 
     expected_output = [0.0179885, 0.0474289, 0.119205, 0.268936, 0.5, 0.731064, 0.880795, 0.952571, 0.982011]
@@ -70,19 +70,19 @@ def eval_function_example():
     cc.Enable(PKESchemeFeature.LEVELEDSHE)
     cc.Enable(PKESchemeFeature.ADVANCEDSHE)
 
-    keyPair = cc.KeyGen()
-    cc.EvalMultKeyGen(keyPair.secretKey)
+    key_pair = cc.KeyGen()
+    cc.EvalMultKeyGen(key_pair.secretKey)
 
     input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
     encoded_length = len(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
-    ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
+    ciphertext = cc.Encrypt(key_pair.publicKey, plaintext)
 
     lower_bound = 1
     upper_bound = 9
     result = cc.EvalChebyshevFunction(math.sqrt,ciphertext, lower_bound, upper_bound, poly_degree)
 
-    plaintext_dec = Decrypt(result, keyPair.secretKey)
+    plaintext_dec = Decrypt(result, key_pair.secretKey)
     plaintext_dec.SetLength(encoded_length)
 
     expected_output = [1, 1.414213, 1.732050, 2, 2.236067, 2.449489, 2.645751, 2.828427, 3]

+ 6 - 6
src/pke/examples/iterative-ckks-bootstrapping.py

@@ -63,10 +63,10 @@ def iterative_bootstrap_example():
     cryptocontext.EvalBootstrapSetup(levelBudget, bsgs_dim, num_slots)
 
     # Step 3: Key generation
-    keyPair = cryptocontext.KeyGen()
-    cryptocontext.EvalMultKeyGen(keyPair.secretKey)
+    key_pair = cryptocontext.KeyGen()
+    cryptocontext.EvalMultKeyGen(key_pair.secretKey)
     # Generate bootstrapping keys.
-    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, num_slots)
+    cryptocontext.EvalBootstrapKeyGen(key_pair.secretKey, num_slots)
 
     # Step 4: Encoding and encryption of inputs
     # Generate random input
@@ -82,12 +82,12 @@ def iterative_bootstrap_example():
     ptxt = cryptocontext.MakeCKKSPackedPlaintext(x, 1, depth -1,None,num_slots)
 
     # Encrypt the encoded vectors
-    ciph = cryptocontext.Encrypt(keyPair.publicKey, ptxt)
+    ciph = cryptocontext.Encrypt(key_pair.publicKey, ptxt)
 
     # Step 5: Measure the precision of a single bootstrapping operation.
     ciphertext_after = cryptocontext.EvalBootstrap(ciph)
 
-    result = Decrypt(ciphertext_after,keyPair.secretKey)
+    result = Decrypt(ciphertext_after,key_pair.secretKey)
     result.SetLength(num_slots)
     precision = calculate_approximation_error(result.GetCKKSPackedValue(),ptxt.GetCKKSPackedValue())
     print(f"Bootstrapping precision after 1 iteration: {precision} bits\n")
@@ -99,7 +99,7 @@ def iterative_bootstrap_example():
     # Step 6: Run bootstrapping with multiple iterations
     ciphertext_two_iterations = cryptocontext.EvalBootstrap(ciph,num_iterations,precision)
 
-    result_two_iterations = Decrypt(ciphertext_two_iterations,keyPair.secretKey)
+    result_two_iterations = Decrypt(ciphertext_two_iterations,key_pair.secretKey)
     result_two_iterations.SetLength(num_slots)
     actual_result = result_two_iterations.GetCKKSPackedValue()
 

+ 5 - 5
src/pke/examples/polynomial-evaluation.py

@@ -23,13 +23,13 @@ def main():
                     0.1, 0.2, 0.3, 0.4, 0.5, -0.1, -0.2, -0.3, -0.4, -0.5]
     plaintext1 = cc.MakeCKKSPackedPlaintext(input)
 
-    keyPair = cc.KeyGen()
+    key_pair = cc.KeyGen()
     
     print("Generating evaluation key for homomorphic multiplication...")
-    cc.EvalMultKeyGen(keyPair.secretKey)
+    cc.EvalMultKeyGen(key_pair.secretKey)
     print("Completed.\n")
 
-    ciphertext1 = cc.Encrypt(keyPair.publicKey, plaintext1)
+    ciphertext1 = cc.Encrypt(key_pair.publicKey, plaintext1)
 
     t = time.time()
     result = cc.EvalPoly(ciphertext1, coefficients1)
@@ -39,11 +39,11 @@ def main():
     result2 = cc.EvalPoly(ciphertext1, coefficients2)
     time_eval_poly2 = time.time() - t
 
-    plaintext_dec = Decrypt(result, keyPair.secretKey)
+    plaintext_dec = Decrypt(result, key_pair.secretKey)
 
     plaintext_dec.SetLength(encoded_length)
 
-    plaintext_dec2 = Decrypt(result2, keyPair.secretKey)
+    plaintext_dec2 = Decrypt(result2, key_pair.secretKey)
 
     plaintext_dec2.SetLength(encoded_length)
 

+ 5 - 5
src/pke/examples/simple-ckks-bootstrapping.py

@@ -44,9 +44,9 @@ def simple_bootstrap_example():
 
     cryptocontext.EvalBootstrapSetup(level_budget)
 
-    keyPair = cryptocontext.KeyGen()
-    cryptocontext.EvalMultKeyGen(keyPair.secretKey)
-    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, num_slots)
+    key_pair = cryptocontext.KeyGen()
+    cryptocontext.EvalMultKeyGen(key_pair.secretKey)
+    cryptocontext.EvalBootstrapKeyGen(key_pair.secretKey, num_slots)
 
     x = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]
     encoded_length = len(x)
@@ -56,7 +56,7 @@ def simple_bootstrap_example():
 
     print(f"Input: {x}")
 
-    ciph = cryptocontext.Encrypt(keyPair.publicKey, ptxt)
+    ciph = cryptocontext.Encrypt(key_pair.publicKey, ptxt)
 
     print(f"Initial number of levels remaining: {ciph.GetLevel()}")
 
@@ -64,7 +64,7 @@ def simple_bootstrap_example():
 
     print(f"Number of levels remaining after bootstrapping: {ciphertext_after.GetLevel()}")
 
-    result = Decrypt(ciphertext_after,keyPair.secretKey)
+    result = Decrypt(ciphertext_after,key_pair.secretKey)
     result.SetLength(encoded_length)
     print(f"Output after bootstrapping: {result}")