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

+ 96 - 96
src/pke/examples/advanced-real-numbers.py

@@ -1,18 +1,18 @@
 from openfhe import *
 from openfhe import *
 import time # to enable TIC-TOC timing measurements
 import time # to enable TIC-TOC timing measurements
 
 
-def AutomaticRescaleDemo(scalTech):
-    if(scalTech == ScalingTechnique.FLEXIBLEAUTO):
+def automatic_rescale_demo(scal_tech):
+    if(scal_tech == ScalingTechnique.FLEXIBLEAUTO):
         print("\n\n\n ===== FlexibleAutoDemo =============\n") 
         print("\n\n\n ===== FlexibleAutoDemo =============\n") 
     else:
     else:
          print("\n\n\n ===== FixedAutoDemo =============\n")
          print("\n\n\n ===== FixedAutoDemo =============\n")
 
 
-    batchSize = 8
+    batch_size = 8
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(5)
     parameters.SetMultiplicativeDepth(5)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
-    parameters.SetScalingTechnique(scalTech)
-    parameters.SetBatchSize(batchSize)
+    parameters.SetScalingTechnique(scal_tech)
+    parameters.SetBatchSize(batch_size)
 
 
     cc = GenCryptoContext(parameters)
     cc = GenCryptoContext(parameters)
 
 
@@ -51,17 +51,17 @@ def AutomaticRescaleDemo(scalTech):
 
 
     result = Decrypt(cRes,keys.secretKey)
     result = Decrypt(cRes,keys.secretKey)
     print("x^18 + x^9 + 1 = ", result)
     print("x^18 + x^9 + 1 = ", result)
-    result.SetLength(batchSize)
+    result.SetLength(batch_size)
     print(f"Result: {result}")
     print(f"Result: {result}")
 
 
-def ManualRescaleDemo(ScalingTechnique):
+def manual_rescale_demo(scal_tech):
     print("\n\n\n ===== FixedManualDemo =============\n")
     print("\n\n\n ===== FixedManualDemo =============\n")
     
     
-    batchSize = 8
+    batch_size = 8
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(5)
     parameters.SetMultiplicativeDepth(5)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
-    parameters.SetBatchSize(batchSize)
+    parameters.SetBatchSize(batch_size)
 
 
     cc = GenCryptoContext(parameters)
     cc = GenCryptoContext(parameters)
 
 
@@ -93,10 +93,10 @@ def ManualRescaleDemo(ScalingTechnique):
     #
     #
 
 
     # x^2
     # x^2
-    c2_depth_2 = cc.EvalMult(c, c)
-    c2_depth_1 = cc.Rescale(c2_depth_2)
+    c2_depth2 = cc.EvalMult(c, c)
+    c2_depth1 = cc.Rescale(c2_depth2)
     # x^4
     # x^4
-    c4_depth2 = cc.EvalMult(c2_depth_1, c2_depth_1)
+    c4_depth2 = cc.EvalMult(c2_depth1, c2_depth1)
     c4_depth1 = cc.Rescale(c4_depth2)
     c4_depth1 = cc.Rescale(c4_depth2)
     # x^8
     # x^8
     c8_depth2 = cc.EvalMult(c4_depth1, c4_depth1)
     c8_depth2 = cc.EvalMult(c4_depth1, c4_depth1)
@@ -107,23 +107,23 @@ def ManualRescaleDemo(ScalingTechnique):
     # x^9
     # x^9
     c9_depth2 = cc.EvalMult(c8_depth1, c)
     c9_depth2 = cc.EvalMult(c8_depth1, c)
     # x^18
     # x^18
-    c18_depth2 = cc.EvalMult(c16_depth1, c2_depth_1)
+    c18_depth2 = cc.EvalMult(c16_depth1, c2_depth1)
     # Final result
     # Final result
     cRes_depth2 = cc.EvalAdd(cc.EvalAdd(c18_depth2, c9_depth2), 1.0)
     cRes_depth2 = cc.EvalAdd(cc.EvalAdd(c18_depth2, c9_depth2), 1.0)
     cRes_depth1 = cc.Rescale(cRes_depth2)
     cRes_depth1 = cc.Rescale(cRes_depth2)
 
 
     result = Decrypt(cRes_depth1,keys.secretKey)
     result = Decrypt(cRes_depth1,keys.secretKey)
-    result.SetLength(batchSize)
+    result.SetLength(batch_size)
     print("x^18 + x^9 + 1 = ", result)
     print("x^18 + x^9 + 1 = ", result)
 
 
-def HybridKeySwitchingDemo1():
-    
+def hybrid_key_switching_demo1():
+    print("\n\n\n ===== hybrid_key_switching_demo1 =============\n")
     dnum = 2
     dnum = 2
-    batchSize = 8
+    batch_size = 8
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(5)
     parameters.SetMultiplicativeDepth(5)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
-    parameters.SetBatchSize(batchSize)
+    parameters.SetBatchSize(batch_size)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetNumLargeDigits(dnum)
     parameters.SetNumLargeDigits(dnum)
 
 
@@ -149,24 +149,24 @@ def HybridKeySwitchingDemo1():
     c = cc.Encrypt(keys.publicKey,ptxt)
     c = cc.Encrypt(keys.publicKey,ptxt)
 
 
     t = time.time()
     t = time.time()
-    cRot1 = cc.EvalRotate(c,1)
-    cRot2 = cc.EvalRotate(cRot1,-2)
+    c_rot1 = cc.EvalRotate(c,1)
+    c_rot2 = cc.EvalRotate(c_rot1,-2)
     time2digits = time.time() - t
     time2digits = time.time() - t
 
 
-    result = Decrypt(cRot2,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_rot2,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"x rotate by -1 = {result}")
     print(f"x rotate by -1 = {result}")
     print(f" - 2 rotations with HYBRID (2 digits) took {time2digits*1000} ms")
     print(f" - 2 rotations with HYBRID (2 digits) took {time2digits*1000} ms")
 
 
 
 
-def HybridKeySwitchingDemo2():
-    print("\n\n\n ===== HybridKeySwitchingDemo2 =============\n")
+def hybrid_key_switching_demo2():
+    print("\n\n\n ===== hybrid_key_switching_demo2 =============\n")
     dnum = 3
     dnum = 3
-    batchSize = 8
+    batch_size = 8
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(5)
     parameters.SetMultiplicativeDepth(5)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
-    parameters.SetBatchSize(batchSize)
+    parameters.SetBatchSize(batch_size)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetNumLargeDigits(dnum)
     parameters.SetNumLargeDigits(dnum)
 
 
@@ -193,19 +193,19 @@ def HybridKeySwitchingDemo2():
     c = cc.Encrypt(keys.publicKey,ptxt)
     c = cc.Encrypt(keys.publicKey,ptxt)
 
 
     t = time.time()
     t = time.time()
-    cRot1 = cc.EvalRotate(c,1)
-    cRot2 = cc.EvalRotate(cRot1,-2)
+    c_rot1 = cc.EvalRotate(c,1)
+    c_rot2 = cc.EvalRotate(c_rot1,-2)
     time3digits = time.time() - t
     time3digits = time.time() - t
     # The runtime here is smaller than the previous demo
     # The runtime here is smaller than the previous demo
 
 
-    result = Decrypt(cRot2,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_rot2,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"x rotate by -1 = {result}")
     print(f"x rotate by -1 = {result}")
     print(f" - 2 rotations with HYBRID (3 digits) took {time3digits*1000} ms")
     print(f" - 2 rotations with HYBRID (3 digits) took {time3digits*1000} ms")
 
 
-def FastRotationDemo1():
-    print("\n\n\n ===== FastRotationDemo1 =============\n")
-    batchSize = 8
+def fast_rotation_demo1():
+    print("\n\n\n ===== fast_rotation_demo1 =============\n")
+    batch_size = 8
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(5)
     parameters.SetMultiplicativeDepth(5)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
@@ -234,63 +234,63 @@ def FastRotationDemo1():
     # First, we perform 7 regular (non-hoisted) rotations
     # First, we perform 7 regular (non-hoisted) rotations
     # and measure the runtime
     # and measure the runtime
     t = time.time()
     t = time.time()
-    cRot1 = cc.EvalRotate(c,1)
-    cRot2 = cc.EvalRotate(c,2)
-    cRot3 = cc.EvalRotate(c,3)
-    cRot4 = cc.EvalRotate(c,4)
-    cRot5 = cc.EvalRotate(c,5)
-    cRot6 = cc.EvalRotate(c,6)
-    cRot7 = cc.EvalRotate(c,7)
-    timeNoHoisting = time.time() - t
+    c_rot1 = cc.EvalRotate(c,1)
+    c_rot2 = cc.EvalRotate(c,2)
+    c_rot3 = cc.EvalRotate(c,3)
+    c_rot4 = cc.EvalRotate(c,4)
+    c_rot5 = cc.EvalRotate(c,5)
+    c_rot6 = cc.EvalRotate(c,6)
+    c_rot7 = cc.EvalRotate(c,7)
+    time_no_hoisting = time.time() - t
 
 
-    cResNoHoist = c + cRot1 + cRot2 + cRot3 + cRot4 + cRot5 + cRot6 + cRot7
+    c_res_no_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
 
 
     # M is the cyclotomic order and we need it to call EvalFastRotation
     # M is the cyclotomic order and we need it to call EvalFastRotation
     M = 2*N
     M = 2*N
 
 
     # Then, we perform 7 rotations with hoisting.
     # Then, we perform 7 rotations with hoisting.
     t = time.time()
     t = time.time()
-    cPrecomp = cc.EvalFastRotationPrecompute(c)
-    cRot1 = cc.EvalFastRotation(c, 1, M, cPrecomp)
-    cRot2 = cc.EvalFastRotation(c, 2, M, cPrecomp)
-    cRot3 = cc.EvalFastRotation(c, 3, M, cPrecomp)
-    cRot4 = cc.EvalFastRotation(c, 4, M, cPrecomp)
-    cRot5 = cc.EvalFastRotation(c, 5, M, cPrecomp)
-    cRot6 = cc.EvalFastRotation(c, 6, M, cPrecomp)
-    cRot7 = cc.EvalFastRotation(c, 7, M, cPrecomp)
-    timeHoisting = time.time() - t
+    c_precomp = cc.EvalFastRotationPrecompute(c)
+    c_rot1 = cc.EvalFastRotation(c,1,M,c_precomp)
+    c_rot2 = cc.EvalFastRotation(c,2,M,c_precomp)
+    c_rot3 = cc.EvalFastRotation(c,3,M,c_precomp)
+    c_rot4 = cc.EvalFastRotation(c,4,M,c_precomp)
+    c_rot5 = cc.EvalFastRotation(c,5,M,c_precomp)
+    c_rot6 = cc.EvalFastRotation(c,6,M,c_precomp)
+    c_rot7 = cc.EvalFastRotation(c,7,M,c_precomp)
+    time_hoisting = time.time() - t
     # The time with hoisting should be faster than without hoisting.
     # The time with hoisting should be faster than without hoisting.
 
 
-    cResHoist = c + cRot1 + cRot2 + cRot3 + cRot4 + cRot5 + cRot6 + cRot7
+    c_res_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
     
     
-    result = Decrypt(cResNoHoist,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"Result without hoisting: {result}")
     print(f"Result without hoisting: {result}")
-    print(f" - 7 rotations without hoisting took {timeNoHoisting*1000} ms")
+    print(f" - 7 rotations without hoisting took {time_no_hoisting*1000} ms")
 
 
     
     
-    result = Decrypt(cResHoist,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_res_hoist,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"Result with hoisting: {result}")
     print(f"Result with hoisting: {result}")
-    print(f" - 7 rotations with hoisting took {timeHoisting*1000} ms")
+    print(f" - 7 rotations with hoisting took {time_hoisting*1000} ms")
 
 
 
 
 
 
 
 
-def FastRotationDemo2():
-    print("\n\n\n ===== FastRotationDemo2 =============\n")
+def fast_rotation_demo2():
+    print("\n\n\n ===== fast_rotation_demo2 =============\n")
 
 
-    digitSize = 3
-    batchSize = 8
+    digit_size = 3
+    batch_size = 8
 
 
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetMultiplicativeDepth(1)
     parameters.SetMultiplicativeDepth(1)
     parameters.SetScalingModSize(50)
     parameters.SetScalingModSize(50)
-    parameters.SetBatchSize(batchSize)
+    parameters.SetBatchSize(batch_size)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetScalingTechnique(ScalingTechnique.FLEXIBLEAUTO)
     parameters.SetKeySwitchTechnique(KeySwitchTechnique.BV)
     parameters.SetKeySwitchTechnique(KeySwitchTechnique.BV)
     parameters.SetFirstModSize(60)
     parameters.SetFirstModSize(60)
-    parameters.SetDigitSize(digitSize)
+    parameters.SetDigitSize(digit_size)
 
 
     cc = GenCryptoContext(parameters)
     cc = GenCryptoContext(parameters)
 
 
@@ -315,31 +315,31 @@ def FastRotationDemo2():
     # First, we perform 7 regular (non-hoisted) rotations
     # First, we perform 7 regular (non-hoisted) rotations
     # and measure the runtime
     # and measure the runtime
     t = time.time()
     t = time.time()
-    cRot1 = cc.EvalRotate(c,1)
-    cRot2 = cc.EvalRotate(c,2)
-    cRot3 = cc.EvalRotate(c,3)
-    cRot4 = cc.EvalRotate(c,4)
-    cRot5 = cc.EvalRotate(c,5)
-    cRot6 = cc.EvalRotate(c,6)
-    cRot7 = cc.EvalRotate(c,7)
-    timeNoHoisting = time.time() - t
+    c_rot1 = cc.EvalRotate(c,1)
+    c_rot2 = cc.EvalRotate(c,2)
+    c_rot3 = cc.EvalRotate(c,3)
+    c_rot4 = cc.EvalRotate(c,4)
+    c_rot5 = cc.EvalRotate(c,5)
+    c_rot6 = cc.EvalRotate(c,6)
+    c_rot7 = cc.EvalRotate(c,7)
+    time_no_hoisting = time.time() - t
 
 
-    cResNoHoist = c + cRot1 + cRot2 + cRot3 + cRot4 + cRot5 + cRot6 + cRot7
+    c_res_no_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
 
 
     # M is the cyclotomic order and we need it to call EvalFastRotation
     # M is the cyclotomic order and we need it to call EvalFastRotation
     M = 2*N
     M = 2*N
 
 
     # Then, we perform 7 rotations with hoisting.
     # Then, we perform 7 rotations with hoisting.
     t = time.time()
     t = time.time()
-    cPrecomp = cc.EvalFastRotationPrecompute(c)
-    cRot1 = cc.EvalFastRotation(c, 1, M, cPrecomp)
-    cRot2 = cc.EvalFastRotation(c, 2, M, cPrecomp)
-    cRot3 = cc.EvalFastRotation(c, 3, M, cPrecomp)
-    cRot4 = cc.EvalFastRotation(c, 4, M, cPrecomp)
-    cRot5 = cc.EvalFastRotation(c, 5, M, cPrecomp)
-    cRot6 = cc.EvalFastRotation(c, 6, M, cPrecomp)
-    cRot7 = cc.EvalFastRotation(c, 7, M, cPrecomp)
-    timeHoisting = time.time() - t
+    c_precomp = cc.EvalFastRotationPrecompute(c)
+    c_rot1 = cc.EvalFastRotation(c,1,M,c_precomp)
+    c_rot2 = cc.EvalFastRotation(c,2,M,c_precomp)
+    c_rot3 = cc.EvalFastRotation(c,3,M,c_precomp)
+    c_rot4 = cc.EvalFastRotation(c,4,M,c_precomp)
+    c_rot5 = cc.EvalFastRotation(c,5,M,c_precomp)
+    c_rot6 = cc.EvalFastRotation(c,6,M,c_precomp)
+    c_rot7 = cc.EvalFastRotation(c,7,M,c_precomp)
+    time_hoisting = time.time() - t
     # The time with hoisting should be faster than without hoisting.
     # The time with hoisting should be faster than without hoisting.
     # Also, the benefits from hoisting should be more pronounced in this
     # Also, the benefits from hoisting should be more pronounced in this
     # case because we're using BV. Of course, we also observe less
     # case because we're using BV. Of course, we also observe less
@@ -347,27 +347,27 @@ def FastRotationDemo2():
     # digitSize = 10 (Users can decrease digitSize to see the accuracy
     # digitSize = 10 (Users can decrease digitSize to see the accuracy
     # increase, and performance decrease).
     # increase, and performance decrease).
 
 
-    cResHoist = c + cRot1 + cRot2 + cRot3 + cRot4 + cRot5 + cRot6 + cRot7
+    c_res_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
 
 
-    result = Decrypt(cResNoHoist,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"Result without hoisting: {result}")
     print(f"Result without hoisting: {result}")
-    print(f" - 7 rotations without hoisting took {timeNoHoisting*1000} ms")
+    print(f" - 7 rotations without hoisting took {time_no_hoisting*1000} ms")
 
 
-    result = Decrypt(cResHoist,keys.secretKey)
-    result.SetLength(batchSize)
+    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result.SetLength(batch_size)
     print(f"Result with hoisting: {result}")
     print(f"Result with hoisting: {result}")
-    print(f" - 7 rotations with hoisting took {timeHoisting*1000} ms")
+    print(f" - 7 rotations with hoisting took {time_hoisting*1000} ms")
 
 
 
 
 def main():
 def main():
-    AutomaticRescaleDemo(ScalingTechnique.FLEXIBLEAUTO)
-    AutomaticRescaleDemo(ScalingTechnique.FIXEDAUTO)
-    ManualRescaleDemo(ScalingTechnique.FIXEDMANUAL)
-    HybridKeySwitchingDemo1()
-    HybridKeySwitchingDemo2()
-    FastRotationDemo1()
-    FastRotationDemo2()
+    automatic_rescale_demo(ScalingTechnique.FLEXIBLEAUTO)
+    automatic_rescale_demo(ScalingTechnique.FIXEDAUTO)
+    manual_rescale_demo(ScalingTechnique.FIXEDMANUAL)
+    hybrid_key_switching_demo1()
+    hybrid_key_switching_demo2()
+    fast_rotation_demo1()
+    fast_rotation_demo2()
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     main()
     main()

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

@@ -2,25 +2,25 @@ from openfhe import *
 import math
 import math
 
 
 def main():
 def main():
-    EvalLogisticExample()
-    EvalFunctionExample()
+    eval_logistic_example()
+    eval_function_example()
 
 
-def EvalLogisticExample():
+def eval_logistic_example():
     print("--------------------------------- EVAL LOGISTIC FUNCTION ---------------------------------\n")
     print("--------------------------------- EVAL LOGISTIC FUNCTION ---------------------------------\n")
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetRingDim(1 << 10)
     parameters.SetRingDim(1 << 10)
 
 
-    scalingModSize = 59
-    firstModSize = 60
+    scaling_mod_size = 59
+    first_mod_size = 60
 
 
-    parameters.SetScalingModSize(scalingModSize)
-    parameters.SetFirstModSize(firstModSize)
+    parameters.SetScalingModSize(scaling_mod_size)
+    parameters.SetFirstModSize(first_mod_size)
 
 
-    polyDegree = 16
-    multDepth = 6
+    poly_degree = 16
+    mult_depth = 6
 
 
-    parameters.SetMultiplicativeDepth(multDepth)
+    parameters.SetMultiplicativeDepth(mult_depth)
     cc = GenCryptoContext(parameters)
     cc = GenCryptoContext(parameters)
     cc.Enable(PKESchemeFeature.PKE)
     cc.Enable(PKESchemeFeature.PKE)
     cc.Enable(PKESchemeFeature.KEYSWITCH)
     cc.Enable(PKESchemeFeature.KEYSWITCH)
@@ -31,39 +31,39 @@ def EvalLogisticExample():
     cc.EvalMultKeyGen(keyPair.secretKey)
     cc.EvalMultKeyGen(keyPair.secretKey)
 
 
     input = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
     input = [-4, -3, -2, -1, 0, 1, 2, 3, 4]
-    encodedLength = len(input)
+    encoded_length = len(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
     ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
     ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
 
 
-    lowerBound = -4
-    upperBound = 4
-    result = cc.EvalLogistic(ciphertext, lowerBound, upperBound, polyDegree)
+    lower_bound = -4
+    upper_bound = 4
+    result = cc.EvalLogistic(ciphertext, lower_bound, upper_bound, poly_degree)
 
 
-    plaitextDec = Decrypt(result, keyPair.secretKey)
-    plaitextDec.SetLength(encodedLength)
+    plaitext_dec = Decrypt(result, keyPair.secretKey)
+    plaitext_dec.SetLength(encoded_length)
 
 
-    expectedOutput = [0.0179885, 0.0474289, 0.119205, 0.268936, 0.5, 0.731064, 0.880795, 0.952571, 0.982011]
-    print(f"Expected output\n\t {expectedOutput}\n")
+    expected_output = [0.0179885, 0.0474289, 0.119205, 0.268936, 0.5, 0.731064, 0.880795, 0.952571, 0.982011]
+    print(f"Expected output\n\t {expected_output}\n")
 
 
-    finalResult = plaitextDec.GetCKKSPackedValue()
-    print(f"Actual output\n\t {finalResult}\n")
+    final_result = plaitextDec.GetCKKSPackedValue()
+    print(f"Actual output\n\t {final_result}\n")
 
 
-def EvalFunctionExample():
+def eval_function_example():
     print("--------------------------------- EVAL SQUARE ROOT FUNCTION ---------------------------------\n")
     print("--------------------------------- EVAL SQUARE ROOT FUNCTION ---------------------------------\n")
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetRingDim(1 << 10)
     parameters.SetRingDim(1 << 10)
 
 
-    scalingModSize = 59
-    firstModSize = 60
+    scaling_mod_size = 59
+    first_mod_size = 60
 
 
-    parameters.SetScalingModSize(scalingModSize)
-    parameters.SetFirstModSize(firstModSize)
+    parameters.SetScalingModSize(scaling_mod_size)
+    parameters.SetFirstModSize(first_mod_size)
 
 
-    polyDegree = 50
-    multDepth = 7
+    poly_degree = 50
+    mult_depth = 7
 
 
-    parameters.SetMultiplicativeDepth(multDepth)
+    parameters.SetMultiplicativeDepth(mult_depth)
     cc = GenCryptoContext(parameters)
     cc = GenCryptoContext(parameters)
     cc.Enable(PKESchemeFeature.PKE)
     cc.Enable(PKESchemeFeature.PKE)
     cc.Enable(PKESchemeFeature.KEYSWITCH)
     cc.Enable(PKESchemeFeature.KEYSWITCH)
@@ -74,21 +74,21 @@ def EvalFunctionExample():
     cc.EvalMultKeyGen(keyPair.secretKey)
     cc.EvalMultKeyGen(keyPair.secretKey)
 
 
     input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
     input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
-    encodedLength = len(input)
+    encoded_length = len(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
     plaintext = cc.MakeCKKSPackedPlaintext(input)
     ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
     ciphertext = cc.Encrypt(keyPair.publicKey, plaintext)
 
 
-    lowerBound = 1
-    upperBound = 9
-    result = cc.EvalChebyshevFunction(math.sqrt,ciphertext, lowerBound, upperBound, polyDegree)
+    lower_bound = 1
+    upper_bound = 9
+    result = cc.EvalChebyshevFunction(math.sqrt,ciphertext, lower_bound, upper_bound, poly_degree)
 
 
-    plaintextDec = Decrypt(result, keyPair.secretKey)
-    plaintextDec.SetLength(encodedLength)
+    plaintext_dec = Decrypt(result, keyPair.secretKey)
+    plaintext_dec.SetLength(encoded_length)
 
 
-    expectedOutput = [1, 1.414213, 1.732050, 2, 2.236067, 2.449489, 2.645751, 2.828427, 3]
-    print(f"Expected output\n\t {expectedOutput}\n")
+    expected_output = [1, 1.414213, 1.732050, 2, 2.236067, 2.449489, 2.645751, 2.828427, 3]
+    print(f"Expected output\n\t {expected_output}\n")
 
 
-    finalResult = plaintextDec.GetCKKSPackedValue()
-    print(f"Actual output\n\t {finalResult}\n")
+    final_result = plaintext_dec.GetCKKSPackedValue()
+    print(f"Actual output\n\t {final_result}\n")
 if __name__ == "__main__":
 if __name__ == "__main__":
     main()
     main()

+ 44 - 50
src/pke/examples/iterative-ckks-bootstrapping.py

@@ -3,48 +3,44 @@ import math
 import random
 import random
 
 
 def main():
 def main():
-    IterativeBootstrapExample()
+    iterative_bootstrap_example()
 
 
-def CalculateApproximationError(result,expectedResult):
-    if len(result) != len(expectedResult):
+def calculate_approximation_error(result,expected_result):
+    if len(result) != len(expected_result):
         raise Exception("Cannot compare vectors with different numbers of elements")
         raise Exception("Cannot compare vectors with different numbers of elements")
     # using the infinity norm
     # using the infinity norm
-    maxError = 0
-    for i in range(len(result)):
-        # error is abs of the difference of real parts
-        error = abs(result[i].real - expectedResult[i].real)
-        if error > maxError:
-            maxError = error
-    # resturn absolute value of log base2 of the error
-    return abs(math.log(maxError,2))
-def IterativeBootstrapExample():
+    # error is abs of the difference of real parts
+    max_error = max([abs(el1.real - el2.real) for (el1, el2) in zip(result, expected_result)])
+    # return absolute value of log base2 of the error
+    return abs(math.log(max_error,2))
+def iterative_bootstrap_example():
     # Step 1: Set CryptoContext
     # Step 1: Set CryptoContext
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
-    secretKeyDist = SecretKeyDist.UNIFORM_TERNARY
-    parameters.SetSecretKeyDist(secretKeyDist)
+    secret_key_dist = SecretKeyDist.UNIFORM_TERNARY
+    parameters.SetSecretKeyDist(secret_key_dist)
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetRingDim(1 << 12)
     parameters.SetRingDim(1 << 12)
 
 
-    rescaleTech = ScalingTechnique.FLEXIBLEAUTO
-    dcrtBits = 59
-    firstMod = 60
+    rescale_tech = ScalingTechnique.FLEXIBLEAUTO
+    dcrt_bits = 59
+    first_mod = 60
 
 
-    parameters.SetScalingModSize(dcrtBits)
-    parameters.SetScalingTechnique(rescaleTech)
-    parameters.SetFirstModSize(firstMod)
+    parameters.SetScalingModSize(dcrt_bits)
+    parameters.SetScalingTechnique(rescale_tech)
+    parameters.SetFirstModSize(first_mod)
 
 
     # Here, we specify the number of iterations to run bootstrapping. 
     # Here, we specify the number of iterations to run bootstrapping. 
     # Note that we currently only support 1 or 2 iterations.
     # Note that we currently only support 1 or 2 iterations.
     # Two iterations should give us approximately double the precision of one iteration.
     # Two iterations should give us approximately double the precision of one iteration.
-    numIterations = 2
+    num_iterations = 2
 
 
-    levelBudget = [3, 3]
+    level_budget = [3, 3]
     # Each extra iteration on top of 1 requires an extra level to be consumed.
     # Each extra iteration on top of 1 requires an extra level to be consumed.
-    approxBootstrappDepth = 8 + (numIterations - 1)
-    bsgsDim = [0,0]
+    approx_bootstrapp_depth = 8 + (num_iterations - 1)
+    bsgs_dim = [0,0]
 
 
-    levelsUsedBeforeBootstrap = 10
-    depth = levelsUsedBeforeBootstrap + FHECKKSRNS.GetBootstrapDepth(approxBootstrappDepth, levelBudget, secretKeyDist)
+    levels_used_before_bootstrap = 10
+    depth = levels_used_before_bootstrap + FHECKKSRNS.GetBootstrapDepth(approx_bootstrapp_depth, level_budget, secret_key_dist)
     parameters.SetMultiplicativeDepth(depth)
     parameters.SetMultiplicativeDepth(depth)
 
 
     # Generate crypto context
     # Generate crypto context
@@ -58,44 +54,42 @@ def IterativeBootstrapExample():
     cryptocontext.Enable(PKESchemeFeature.ADVANCEDSHE)
     cryptocontext.Enable(PKESchemeFeature.ADVANCEDSHE)
     cryptocontext.Enable(PKESchemeFeature.FHE)
     cryptocontext.Enable(PKESchemeFeature.FHE)
 
 
-    ringDim = cryptocontext.GetRingDimension()
-    print(f"CKKS is using ring dimension {ringDim}\n\n")
+    ring_dim = cryptocontext.GetRingDimension()
+    print(f"CKKS is using ring dimension {ring_dim}\n\n")
 
 
     # Step 2: Precomputations for bootstrapping
     # Step 2: Precomputations for bootstrapping
     # We use a sparse packing
     # We use a sparse packing
-    numSlots = 8
-    cryptocontext.EvalBootstrapSetup(levelBudget, bsgsDim, numSlots)
+    num_slots = 8
+    cryptocontext.EvalBootstrapSetup(levelBudget, bsgs_dim, num_slots)
 
 
     # Step 3: Key generation
     # Step 3: Key generation
     keyPair = cryptocontext.KeyGen()
     keyPair = cryptocontext.KeyGen()
     cryptocontext.EvalMultKeyGen(keyPair.secretKey)
     cryptocontext.EvalMultKeyGen(keyPair.secretKey)
     # Generate bootstrapping keys.
     # Generate bootstrapping keys.
-    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, numSlots)
+    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, num_slots)
 
 
     # Step 4: Encoding and encryption of inputs
     # Step 4: Encoding and encryption of inputs
     # Generate random input
     # Generate random input
-    x = []
-    for i in range(numSlots):
-        x.append(random.uniform(0, 1))
+    x = [random.uniform(0, 1) for i in range(num_slots)]
 
 
     """ Encoding as plaintexts
     """ Encoding as plaintexts
-        We specify the number of slots as numSlots to achieve a performance improvement.
+        We specify the number of slots as num_slots to achieve a performance improvement.
         We use the other default values of depth 1, levels 0, and no params.
         We use the other default values of depth 1, levels 0, and no params.
         Alternatively, you can also set batch size as a parameter in the CryptoContext as follows:
         Alternatively, you can also set batch size as a parameter in the CryptoContext as follows:
-        parameters.SetBatchSize(numSlots);
-        Here, we assume all ciphertexts in the cryptoContext will have numSlots slots.
+        parameters.SetBatchSize(num_slots);
+        Here, we assume all ciphertexts in the cryptoContext will have num_slots slots.
         We start with a depleted ciphertext that has used up all of its levels."""
         We start with a depleted ciphertext that has used up all of its levels."""
-    ptxt = cryptocontext.MakeCKKSPackedPlaintext(x, 1, depth -1,None,numSlots)
+    ptxt = cryptocontext.MakeCKKSPackedPlaintext(x, 1, depth -1,None,num_slots)
 
 
     # Encrypt the encoded vectors
     # Encrypt the encoded vectors
     ciph = cryptocontext.Encrypt(keyPair.publicKey, ptxt)
     ciph = cryptocontext.Encrypt(keyPair.publicKey, ptxt)
 
 
     # Step 5: Measure the precision of a single bootstrapping operation.
     # Step 5: Measure the precision of a single bootstrapping operation.
-    ciphertextAfter = cryptocontext.EvalBootstrap(ciph)
+    ciphertext_after = cryptocontext.EvalBootstrap(ciph)
 
 
-    result = Decrypt(ciphertextAfter,keyPair.secretKey)
-    result.SetLength(numSlots)
-    precision = CalculateApproximationError(result.GetCKKSPackedValue(),ptxt.GetCKKSPackedValue())
+    result = Decrypt(ciphertext_after,keyPair.secretKey)
+    result.SetLength(num_slots)
+    precision = calculate_approximation_error(result.GetCKKSPackedValue(),ptxt.GetCKKSPackedValue())
     print(f"Bootstrapping precision after 1 iteration: {precision} bits\n")
     print(f"Bootstrapping precision after 1 iteration: {precision} bits\n")
 
 
     # Set the precision equal to empirically measured value after many test runs.
     # Set the precision equal to empirically measured value after many test runs.
@@ -103,17 +97,17 @@ def IterativeBootstrapExample():
     print(f"Precision input to algorithm: {precision}\n")
     print(f"Precision input to algorithm: {precision}\n")
 
 
     # Step 6: Run bootstrapping with multiple iterations
     # Step 6: Run bootstrapping with multiple iterations
-    ciphertextTwoIterations = cryptocontext.EvalBootstrap(ciph,numIterations,precision)
+    ciphertext_two_iterations = cryptocontext.EvalBootstrap(ciph,num_iterations,precision)
 
 
-    resultTwoIterations = Decrypt(ciphertextTwoIterations,keyPair.secretKey)
-    resultTwoIterations.SetLength(numSlots)
-    actualResult = resultTwoIterations.GetCKKSPackedValue()
+    result_two_iterations = Decrypt(ciphertext_two_iterations,keyPair.secretKey)
+    result_two_iterations.SetLength(num_slots)
+    actual_result = result_two_iterations.GetCKKSPackedValue()
 
 
-    print(f"Output after two interations of bootstrapping: {actualResult}\n")
-    precisionMultipleIterations = CalculateApproximationError(actualResult,ptxt.GetCKKSPackedValue())
+    print(f"Output after two interations of bootstrapping: {actual_result}\n")
+    precision_multiple_iterations = calculate_approximation_error(actual_result,ptxt.GetCKKSPackedValue())
 
 
-    print(f"Bootstrapping precision after 2 iterations: {precisionMultipleIterations} bits\n")
-    print(f"Number of levels remaining after 2 bootstrappings: {depth - ciphertextTwoIterations.GetLevel()}\n")
+    print(f"Bootstrapping precision after 2 iterations: {precision_multiple_iterations} bits\n")
+    print(f"Number of levels remaining after 2 bootstrappings: {depth - ciphertext_two_iterations.GetLevel()}\n")
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     main()
     main()

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

@@ -16,7 +16,7 @@ def main():
 
 
     input = [complex(a,0) for a in [0.5, 0.7, 0.9, 0.95, 0.93]]
     input = [complex(a,0) for a in [0.5, 0.7, 0.9, 0.95, 0.93]]
     # input = [0.5, 0.7, 0.9, 0.95, 0.93]
     # input = [0.5, 0.7, 0.9, 0.95, 0.93]
-    encodedLength = len(input)
+    encoded_length = len(input)
     coefficients1 = [0.15, 0.75, 0, 1.25, 0, 0, 1, 0, 1, 2, 0, 1, 0, 0, 0, 0, 1]
     coefficients1 = [0.15, 0.75, 0, 1.25, 0, 0, 1, 0, 1, 2, 0, 1, 0, 0, 0, 0, 1]
     coefficients2 = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5,
     coefficients2 = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5,
                     0.1, 0.2, 0.3, 0.4, 0.5, -0.1, -0.2, -0.3, -0.4, -0.5,
                     0.1, 0.2, 0.3, 0.4, 0.5, -0.1, -0.2, -0.3, -0.4, -0.5,
@@ -33,38 +33,38 @@ def main():
 
 
     t = time.time()
     t = time.time()
     result = cc.EvalPoly(ciphertext1, coefficients1)
     result = cc.EvalPoly(ciphertext1, coefficients1)
-    timeEvalPoly1 = time.time() - t
+    time_eval_poly1 = time.time() - t
 
 
     t = time.time()
     t = time.time()
     result2 = cc.EvalPoly(ciphertext1, coefficients2)
     result2 = cc.EvalPoly(ciphertext1, coefficients2)
-    timeEvalPoly2 = time.time() - t
+    time_eval_poly2 = time.time() - t
 
 
-    plaintextDec = Decrypt(result, keyPair.secretKey)
+    plaintext_dec = Decrypt(result, keyPair.secretKey)
 
 
-    plaintextDec.SetLength(encodedLength)
+    plaintext_dec.SetLength(encoded_length)
 
 
-    plaintextDec2 = Decrypt(result2, keyPair.secretKey)
+    plaintext_dec2 = Decrypt(result2, keyPair.secretKey)
 
 
-    plaintextDec2.SetLength(encodedLength)
+    plaintext_dec2.SetLength(encoded_length)
 
 
     print("\n Original Plaintext #1: \n")
     print("\n Original Plaintext #1: \n")
     print(plaintext1)
     print(plaintext1)
 
 
     print(f"\n Result of evaluating a polynomial with coefficients {coefficients1}: \n")
     print(f"\n Result of evaluating a polynomial with coefficients {coefficients1}: \n")
-    print(plaintextDec)
+    print(plaintext_dec)
 
 
     print("\n Expected result: (0.70519107, 1.38285078, 3.97211180, "
     print("\n Expected result: (0.70519107, 1.38285078, 3.97211180, "
                  "5.60215665, 4.86357575) \n") 
                  "5.60215665, 4.86357575) \n") 
 
 
-    print(f"\n Evaluation time: {timeEvalPoly1*1000} ms \n")
+    print(f"\n Evaluation time: {time_eval_poly1*1000} ms \n")
 
 
     print(f"\n Result of evaluating a polynomial with coefficients {coefficients2}: \n")
     print(f"\n Result of evaluating a polynomial with coefficients {coefficients2}: \n")
-    print(plaintextDec2)  
+    print(plaintext_dec2)  
 
 
     print("\n Expected result: (3.4515092326, 5.3752765397, 4.8993108833, "
     print("\n Expected result: (3.4515092326, 5.3752765397, 4.8993108833, "
                  "3.2495023573, 4.0485229982) \n")
                  "3.2495023573, 4.0485229982) \n")
 
 
-    print(f"\n Evaluation time: {timeEvalPoly2*1000} ms \n")
+    print(f"\n Evaluation time: {time_eval_poly2*1000} ms \n")
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     main() 
     main() 

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

@@ -1,31 +1,31 @@
 from openfhe import *
 from openfhe import *
 
 
 def main():
 def main():
-    SimpleBootstrapExample()
+    simple_bootstrap_example()
 
 
-def SimpleBootstrapExample():
+def simple_bootstrap_example():
     parameters = CCParamsCKKSRNS()
     parameters = CCParamsCKKSRNS()
 
 
-    secretKeyDist = SecretKeyDist.UNIFORM_TERNARY
-    parameters.SetSecretKeyDist(secretKeyDist)
+    secret_key_dist = SecretKeyDist.UNIFORM_TERNARY
+    parameters.SetSecretKeyDist(secret_key_dist)
 
 
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
     parameters.SetRingDim(1<<12)
     parameters.SetRingDim(1<<12)
 
 
-    rescaleTech = ScalingTechnique.FLEXIBLEAUTO
-    dcrtBits = 59
-    firstMod = 60
+    rescale_tech = ScalingTechnique.FLEXIBLEAUTO
+    dcrt_bits = 59
+    first_mod = 60
     
     
-    parameters.SetScalingModSize(dcrtBits)
-    parameters.SetScalingTechnique(rescaleTech)
-    parameters.SetFirstModSize(firstMod)
+    parameters.SetScalingModSize(dcrt_bits)
+    parameters.SetScalingTechnique(rescale_tech)
+    parameters.SetFirstModSize(first_mod)
 
 
-    levelBudget = [4, 4]
-    approxBootstrappDepth = 8
+    level_budget = [4, 4]
+    approx_bootstrapp_depth = 8
 
 
-    levelsUsedBeforeBootstrap = 10
+    levels_used_before_bootstrap = 10
 
 
-    depth = levelsUsedBeforeBootstrap + FHECKKSRNS.GetBootstrapDepth(approxBootstrappDepth, levelBudget, secretKeyDist)
+    depth = levels_used_before_bootstrap + FHECKKSRNS.GetBootstrapDepth(approx_bootstrapp_depth, level_budget, secret_key_dist)
 
 
     parameters.SetMultiplicativeDepth(depth)
     parameters.SetMultiplicativeDepth(depth)
 
 
@@ -36,23 +36,23 @@ def SimpleBootstrapExample():
     cryptocontext.Enable(PKESchemeFeature.ADVANCEDSHE)
     cryptocontext.Enable(PKESchemeFeature.ADVANCEDSHE)
     cryptocontext.Enable(PKESchemeFeature.FHE)
     cryptocontext.Enable(PKESchemeFeature.FHE)
 
 
-    ringDim = cryptocontext.GetRingDimension()
+    ring_dim = cryptocontext.GetRingDimension()
     # This is the mazimum number of slots that can be used full packing.
     # This is the mazimum number of slots that can be used full packing.
 
 
-    numSlots = int(ringDim / 2)
-    print(f"CKKS is using ring dimension {ringDim}")
+    num_slots = int(ring_dim / 2)
+    print(f"CKKS is using ring dimension {ring_dim}")
 
 
-    cryptocontext.EvalBootstrapSetup(levelBudget)
+    cryptocontext.EvalBootstrapSetup(level_budget)
 
 
     keyPair = cryptocontext.KeyGen()
     keyPair = cryptocontext.KeyGen()
     cryptocontext.EvalMultKeyGen(keyPair.secretKey)
     cryptocontext.EvalMultKeyGen(keyPair.secretKey)
-    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, numSlots)
+    cryptocontext.EvalBootstrapKeyGen(keyPair.secretKey, num_slots)
 
 
     x = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]
     x = [0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0]
-    encodedLength = len(x)
+    encoded_length = len(x)
 
 
     ptxt = cryptocontext.MakeCKKSPackedPlaintext(x)
     ptxt = cryptocontext.MakeCKKSPackedPlaintext(x)
-    ptxt.SetLength(encodedLength)
+    ptxt.SetLength(encoded_length)
 
 
     print(f"Input: {x}")
     print(f"Input: {x}")
 
 
@@ -60,12 +60,12 @@ def SimpleBootstrapExample():
 
 
     print(f"Initial number of levels remaining: {ciph.GetLevel()}")
     print(f"Initial number of levels remaining: {ciph.GetLevel()}")
 
 
-    ciphertextAfter = cryptocontext.EvalBootstrap(ciph)
+    ciphertext_after = cryptocontext.EvalBootstrap(ciph)
 
 
-    print(f"Number of levels remaining after bootstrapping: {ciphertextAfter.GetLevel()}")
+    print(f"Number of levels remaining after bootstrapping: {ciphertext_after.GetLevel()}")
 
 
-    result = Decrypt(ciphertextAfter,keyPair.secretKey)
-    result.SetLength(encodedLength)
+    result = Decrypt(ciphertext_after,keyPair.secretKey)
+    result.SetLength(encoded_length)
     print(f"Output after bootstrapping: {result}")
     print(f"Output after bootstrapping: {result}")
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':

+ 38 - 36
src/pke/examples/simple-integers-bgvrns.py

@@ -1,82 +1,84 @@
 # Initial Settings
 # Initial Settings
 from openfhe import *
 from openfhe import *
+# import openfhe.PKESchemeFeature as Feature
+
 
 
 # Sample Program: Step 1: Set CryptoContext
 # Sample Program: Step 1: Set CryptoContext
 parameters = CCParamsBGVRNS()
 parameters = CCParamsBGVRNS()
 parameters.SetPlaintextModulus(65537)
 parameters.SetPlaintextModulus(65537)
 parameters.SetMultiplicativeDepth(2)
 parameters.SetMultiplicativeDepth(2)
 
 
-cryptoContext = GenCryptoContext(parameters)
+crypto_context = GenCryptoContext(parameters)
 # Enable features that you wish to use
 # Enable features that you wish to use
-cryptoContext.Enable(PKESchemeFeature.PKE)
-cryptoContext.Enable(PKESchemeFeature.KEYSWITCH)
-cryptoContext.Enable(PKESchemeFeature.LEVELEDSHE)
+crypto_context.Enable(PKESchemeFeature.PKE)
+crypto_context.Enable(PKESchemeFeature.KEYSWITCH)
+crypto_context.Enable(PKESchemeFeature.LEVELEDSHE)
 
 
 # Sample Program: Step 2: Key Generation
 # Sample Program: Step 2: Key Generation
 
 
 # Generate a public/private key pair
 # Generate a public/private key pair
-keypair = cryptoContext.KeyGen()
+key_pair = crypto_context.KeyGen()
 
 
 # Generate the relinearization key
 # Generate the relinearization key
-cryptoContext.EvalMultKeyGen(keypair.secretKey)
+crypto_context.EvalMultKeyGen(key_pair.secretKey)
 
 
 # Generate the rotation evaluation keys
 # Generate the rotation evaluation keys
-cryptoContext.EvalRotateKeyGen(keypair.secretKey, [1, 2, -1, -2])
+crypto_context.EvalRotateKeyGen(key_pair.secretKey, [1, 2, -1, -2])
 
 
 # Sample Program: Step 3: Encryption
 # Sample Program: Step 3: Encryption
 
 
 # First plaintext vector is encoded
 # First plaintext vector is encoded
-vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext1 = cryptoContext.MakePackedPlaintext(vectorOfInts1)
+vector_of_ints1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext1 = crypto_context.MakePackedPlaintext(vector_of_ints1)
 
 
 # Second plaintext vector is encoded
 # Second plaintext vector is encoded
-vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext2 = cryptoContext.MakePackedPlaintext(vectorOfInts2)
+vector_of_ints2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext2 = crypto_context.MakePackedPlaintext(vector_of_ints2)
 
 
 # Third plaintext vector is encoded
 # Third plaintext vector is encoded
-vectorOfInts3 = [1, 2, 5, 2, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext3 = cryptoContext.MakePackedPlaintext(vectorOfInts3)
+vector_of_ints3 = [1, 2, 5, 2, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext3 = crypto_context.MakePackedPlaintext(vector_of_ints3)
 
 
 # The encoded vectors are encrypted
 # The encoded vectors are encrypted
-ciphertext1 = cryptoContext.Encrypt(keypair.publicKey, plaintext1)
-ciphertext2 = cryptoContext.Encrypt(keypair.publicKey, plaintext2)
-ciphertext3 = cryptoContext.Encrypt(keypair.publicKey, plaintext3)
+ciphertext1 = crypto_context.Encrypt(key_pair.publicKey, plaintext1)
+ciphertext2 = crypto_context.Encrypt(key_pair.publicKey, plaintext2)
+ciphertext3 = crypto_context.Encrypt(key_pair.publicKey, plaintext3)
 
 
 #  Sample Program: Step 4: Evaluation
 #  Sample Program: Step 4: Evaluation
 
 
 # Homomorphic additions
 # Homomorphic additions
-ciphertextAdd12 = cryptoContext.EvalAdd(ciphertext1, ciphertext2)
-ciphertextAddResult = cryptoContext.EvalAdd(ciphertextAdd12, ciphertext3)
+ciphertext_add12 = crypto_context.EvalAdd(ciphertext1, ciphertext2)
+ciphertext_add_result = crypto_context.EvalAdd(ciphertext_add12, ciphertext3)
 
 
 # Homomorphic Multiplication
 # Homomorphic Multiplication
-ciphertextMult12 = cryptoContext.EvalMult(ciphertext1, ciphertext2)
-ciphertextMultResult = cryptoContext.EvalMult(ciphertextMult12, ciphertext3)
+ciphertext_mult12 = crypto_context.EvalMult(ciphertext1, ciphertext2)
+ciphertext_mult_result = crypto_context.EvalMult(ciphertext_mult12, ciphertext3)
 
 
 # Homomorphic Rotations
 # Homomorphic Rotations
-ciphertextRot1 = cryptoContext.EvalRotate(ciphertext1, 1)
-ciphertextRot2 = cryptoContext.EvalRotate(ciphertext1, 2)
-ciphertextRot3 = cryptoContext.EvalRotate(ciphertext1, -1)
-ciphertextRot4 = cryptoContext.EvalRotate(ciphertext1, -2)
+ciphertext_rot1 = crypto_context.EvalRotate(ciphertext1, 1)
+ciphertext_rot2 = crypto_context.EvalRotate(ciphertext1, 2)
+ciphertext_rot3 = crypto_context.EvalRotate(ciphertext1, -1)
+ciphertext_rot4 = crypto_context.EvalRotate(ciphertext1, -2)
 
 
 # Sample Program: Step 5: Decryption
 # Sample Program: Step 5: Decryption
 
 
 # Decrypt the result of additions
 # Decrypt the result of additions
-plaintextAddResult = Decrypt(ciphertextAddResult,keypair.secretKey)
+plaintext_add_result = Decrypt(ciphertext_add_result,key_pair.secretKey)
 
 
 # Decrypt the result of multiplications
 # Decrypt the result of multiplications
-plaintextMultResult = Decrypt(ciphertextMultResult,keypair.secretKey)
+plaintext_mult_result = Decrypt(ciphertext_mult_result,key_pair.secretKey)
 
 
 # Decrypt the result of rotations
 # Decrypt the result of rotations
-plaintextRot1 = Decrypt(ciphertextRot1,keypair.secretKey)
-plaintextRot2 = Decrypt(ciphertextRot2,keypair.secretKey)
-plaintextRot3 = Decrypt(ciphertextRot3,keypair.secretKey)
-plaintextRot4 = Decrypt(ciphertextRot4,keypair.secretKey)
+plaintextRot1 = Decrypt(ciphertext_rot1,key_pair.secretKey)
+plaintextRot2 = Decrypt(ciphertext_rot2,key_pair.secretKey)
+plaintextRot3 = Decrypt(ciphertext_rot3,key_pair.secretKey)
+plaintextRot4 = Decrypt(ciphertext_rot4,key_pair.secretKey)
 
 
 
 
-plaintextRot1.SetLength(len(vectorOfInts1))
-plaintextRot2.SetLength(len(vectorOfInts1))
-plaintextRot3.SetLength(len(vectorOfInts1))
-plaintextRot4.SetLength(len(vectorOfInts1))
+plaintextRot1.SetLength(len(vector_of_ints1))
+plaintextRot2.SetLength(len(vector_of_ints1))
+plaintextRot3.SetLength(len(vector_of_ints1))
+plaintextRot4.SetLength(len(vector_of_ints1))
 
 
 print("Plaintext #1: " + str(plaintext1))
 print("Plaintext #1: " + str(plaintext1))
 print("Plaintext #2: " + str(plaintext2))
 print("Plaintext #2: " + str(plaintext2))
@@ -84,8 +86,8 @@ print("Plaintext #3: " + str(plaintext3))
 
 
 # Output Results
 # Output Results
 print("\nResults of homomorphic computations")
 print("\nResults of homomorphic computations")
-print("#1 + #2 + #3 = " + str(plaintextAddResult))
-print("#1 * #2 * #3 = " + str(plaintextMultResult))
+print("#1 + #2 + #3 = " + str(plaintext_add_result))
+print("#1 * #2 * #3 = " + str(plaintext_mult_result))
 print("Left rotation of #1 by 1 = " + str(plaintextRot1))
 print("Left rotation of #1 by 1 = " + str(plaintextRot1))
 print("Left rotation of #1 by 2 = " + str(plaintextRot2))
 print("Left rotation of #1 by 2 = " + str(plaintextRot2))
 print("Right rotation of #1 by 1 = " + str(plaintextRot3))
 print("Right rotation of #1 by 1 = " + str(plaintextRot3))

+ 36 - 36
src/pke/examples/simple-integers.py

@@ -8,77 +8,77 @@ parameters = CCParamsBFVRNS()
 parameters.SetPlaintextModulus(65537)
 parameters.SetPlaintextModulus(65537)
 parameters.SetMultiplicativeDepth(2)
 parameters.SetMultiplicativeDepth(2)
 
 
-cryptoContext = GenCryptoContext(parameters)
+crypto_context = GenCryptoContext(parameters)
 # Enable features that you wish to use
 # Enable features that you wish to use
-cryptoContext.Enable(PKESchemeFeature.PKE)
-cryptoContext.Enable(PKESchemeFeature.KEYSWITCH)
-cryptoContext.Enable(PKESchemeFeature.LEVELEDSHE)
+crypto_context.Enable(PKESchemeFeature.PKE)
+crypto_context.Enable(PKESchemeFeature.KEYSWITCH)
+crypto_context.Enable(PKESchemeFeature.LEVELEDSHE)
 
 
 # Sample Program: Step 2: Key Generation
 # Sample Program: Step 2: Key Generation
 
 
 # Generate a public/private key pair
 # Generate a public/private key pair
-keypair = cryptoContext.KeyGen()
+key_pair = crypto_context.KeyGen()
 
 
 # Generate the relinearization key
 # Generate the relinearization key
-cryptoContext.EvalMultKeyGen(keypair.secretKey)
+crypto_context.EvalMultKeyGen(key_pair.secretKey)
 
 
 # Generate the rotation evaluation keys
 # Generate the rotation evaluation keys
-cryptoContext.EvalRotateKeyGen(keypair.secretKey, [1, 2, -1, -2])
+crypto_context.EvalRotateKeyGen(key_pair.secretKey, [1, 2, -1, -2])
 
 
 # Sample Program: Step 3: Encryption
 # Sample Program: Step 3: Encryption
 
 
 # First plaintext vector is encoded
 # First plaintext vector is encoded
-vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext1 = cryptoContext.MakePackedPlaintext(vectorOfInts1)
+vector_of_ints1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext1 = crypto_context.MakePackedPlaintext(vector_of_ints1)
 
 
 # Second plaintext vector is encoded
 # Second plaintext vector is encoded
-vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext2 = cryptoContext.MakePackedPlaintext(vectorOfInts2)
+vector_of_ints2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext2 = crypto_context.MakePackedPlaintext(vector_of_ints2)
 
 
 # Third plaintext vector is encoded
 # Third plaintext vector is encoded
-vectorOfInts3 = [1, 2, 5, 2, 5, 6, 7, 8, 9, 10, 11, 12]
-plaintext3 = cryptoContext.MakePackedPlaintext(vectorOfInts3)
+vector_of_ints3 = [1, 2, 5, 2, 5, 6, 7, 8, 9, 10, 11, 12]
+plaintext3 = crypto_context.MakePackedPlaintext(vector_of_ints3)
 
 
 # The encoded vectors are encrypted
 # The encoded vectors are encrypted
-ciphertext1 = cryptoContext.Encrypt(keypair.publicKey, plaintext1)
-ciphertext2 = cryptoContext.Encrypt(keypair.publicKey, plaintext2)
-ciphertext3 = cryptoContext.Encrypt(keypair.publicKey, plaintext3)
+ciphertext1 = crypto_context.Encrypt(key_pair.publicKey, plaintext1)
+ciphertext2 = crypto_context.Encrypt(key_pair.publicKey, plaintext2)
+ciphertext3 = crypto_context.Encrypt(key_pair.publicKey, plaintext3)
 
 
 #  Sample Program: Step 4: Evaluation
 #  Sample Program: Step 4: Evaluation
 
 
 # Homomorphic additions
 # Homomorphic additions
-ciphertextAdd12 = cryptoContext.EvalAdd(ciphertext1, ciphertext2)
-ciphertextAddResult = cryptoContext.EvalAdd(ciphertextAdd12, ciphertext3)
+ciphertext_add12 = crypto_context.EvalAdd(ciphertext1, ciphertext2)
+ciphertext_add_result = crypto_context.EvalAdd(ciphertext_add12, ciphertext3)
 
 
 # Homomorphic Multiplication
 # Homomorphic Multiplication
-ciphertextMult12 = cryptoContext.EvalMult(ciphertext1, ciphertext2)
-ciphertextMultResult = cryptoContext.EvalMult(ciphertextMult12, ciphertext3)
+ciphertext_mult12 = crypto_context.EvalMult(ciphertext1, ciphertext2)
+ciphertext_mult_result = crypto_context.EvalMult(ciphertext_mult12, ciphertext3)
 
 
 # Homomorphic Rotations
 # Homomorphic Rotations
-ciphertextRot1 = cryptoContext.EvalRotate(ciphertext1, 1)
-ciphertextRot2 = cryptoContext.EvalRotate(ciphertext1, 2)
-ciphertextRot3 = cryptoContext.EvalRotate(ciphertext1, -1)
-ciphertextRot4 = cryptoContext.EvalRotate(ciphertext1, -2)
+ciphertext_rot1 = crypto_context.EvalRotate(ciphertext1, 1)
+ciphertext_rot2 = crypto_context.EvalRotate(ciphertext1, 2)
+ciphertext_rot3 = crypto_context.EvalRotate(ciphertext1, -1)
+ciphertext_rot4 = crypto_context.EvalRotate(ciphertext1, -2)
 
 
 # Sample Program: Step 5: Decryption
 # Sample Program: Step 5: Decryption
 
 
 # Decrypt the result of additions
 # Decrypt the result of additions
-plaintextAddResult = Decrypt(ciphertextAddResult,keypair.secretKey)
+plaintext_add_result = Decrypt(ciphertext_add_result,key_pair.secretKey)
 
 
 # Decrypt the result of multiplications
 # Decrypt the result of multiplications
-plaintextMultResult = Decrypt(ciphertextMultResult,keypair.secretKey)
+plaintext_mult_result = Decrypt(ciphertext_mult_result,key_pair.secretKey)
 
 
 # Decrypt the result of rotations
 # Decrypt the result of rotations
-plaintextRot1 = Decrypt(ciphertextRot1,keypair.secretKey)
-plaintextRot2 = Decrypt(ciphertextRot2,keypair.secretKey)
-plaintextRot3 = Decrypt(ciphertextRot3,keypair.secretKey)
-plaintextRot4 = Decrypt(ciphertextRot4,keypair.secretKey)
+plaintextRot1 = Decrypt(ciphertext_rot1,key_pair.secretKey)
+plaintextRot2 = Decrypt(ciphertext_rot2,key_pair.secretKey)
+plaintextRot3 = Decrypt(ciphertext_rot3,key_pair.secretKey)
+plaintextRot4 = Decrypt(ciphertext_rot4,key_pair.secretKey)
 
 
 
 
-plaintextRot1.SetLength(len(vectorOfInts1))
-plaintextRot2.SetLength(len(vectorOfInts1))
-plaintextRot3.SetLength(len(vectorOfInts1))
-plaintextRot4.SetLength(len(vectorOfInts1))
+plaintextRot1.SetLength(len(vector_of_ints1))
+plaintextRot2.SetLength(len(vector_of_ints1))
+plaintextRot3.SetLength(len(vector_of_ints1))
+plaintextRot4.SetLength(len(vector_of_ints1))
 
 
 print("Plaintext #1: " + str(plaintext1))
 print("Plaintext #1: " + str(plaintext1))
 print("Plaintext #2: " + str(plaintext2))
 print("Plaintext #2: " + str(plaintext2))
@@ -86,8 +86,8 @@ print("Plaintext #3: " + str(plaintext3))
 
 
 # Output Results
 # Output Results
 print("\nResults of homomorphic computations")
 print("\nResults of homomorphic computations")
-print("#1 + #2 + #3 = " + str(plaintextAddResult))
-print("#1 * #2 * #3 = " + str(plaintextMultResult))
+print("#1 + #2 + #3 = " + str(plaintext_add_result))
+print("#1 * #2 * #3 = " + str(plaintext_mult_result))
 print("Left rotation of #1 by 1 = " + str(plaintextRot1))
 print("Left rotation of #1 by 1 = " + str(plaintextRot1))
 print("Left rotation of #1 by 2 = " + str(plaintextRot2))
 print("Left rotation of #1 by 2 = " + str(plaintextRot2))
 print("Right rotation of #1 by 1 = " + str(plaintextRot3))
 print("Right rotation of #1 by 1 = " + str(plaintextRot3))

+ 22 - 22
src/pke/examples/simple-real-numbers.py

@@ -1,13 +1,13 @@
 from openfhe import *
 from openfhe import *
 
 
-multDepth = 1
-scaleModSize = 50
-batchSize = 8
+mult_depth = 1
+scale_mod_size = 50
+batch_size = 8
 
 
 parameters = CCParamsCKKSRNS()
 parameters = CCParamsCKKSRNS()
-parameters.SetMultiplicativeDepth(multDepth)
-parameters.SetScalingModSize(scaleModSize)
-parameters.SetBatchSize(batchSize)
+parameters.SetMultiplicativeDepth(mult_depth)
+parameters.SetScalingModSize(scale_mod_size)
+parameters.SetBatchSize(batch_size)
 
 
 cc = GenCryptoContext(parameters)
 cc = GenCryptoContext(parameters)
 cc.Enable(PKESchemeFeature.PKE)
 cc.Enable(PKESchemeFeature.PKE)
@@ -35,20 +35,20 @@ c2 = cc.Encrypt(keys.publicKey, ptx2)
 
 
 # Step 4: Evaluation
 # Step 4: Evaluation
 # Homomorphic additions
 # Homomorphic additions
-cAdd = cc.EvalAdd(c1, c2)
+c_add = cc.EvalAdd(c1, c2)
 # Homomorphic subtraction
 # Homomorphic subtraction
-cSub = cc.EvalSub(c1, c2)
+c_sub = cc.EvalSub(c1, c2)
 # Homomorphic scalar multiplication
 # Homomorphic scalar multiplication
-cScalar = cc.EvalMult(c1,4)
+c_scalar = cc.EvalMult(c1,4)
 # Homomorphic multiplication
 # Homomorphic multiplication
-cMult = cc.EvalMult(c1, c2)
+c_mult = cc.EvalMult(c1, c2)
 # Homomorphic rotations
 # Homomorphic rotations
-cRot1 = cc.EvalRotate(c1, 1)
-cRot2 = cc.EvalRotate(c1, -2)
+c_rot1 = cc.EvalRotate(c1, 1)
+c_rot2 = cc.EvalRotate(c1, -2)
 
 
 # Step 5: Decryption and output
 # Step 5: Decryption and output
 # Decrypt the result of additions
 # Decrypt the result of additions
-ptAdd = Decrypt(cAdd,keys.secretKey)
+ptAdd = Decrypt(c_add,keys.secretKey)
 
 
 # We set the precision to 8 decimal digits for a nicer output.
 # We set the precision to 8 decimal digits for a nicer output.
 # If you want to see the error/noise introduced by CKKS, bump it up
 # If you want to see the error/noise introduced by CKKS, bump it up
@@ -57,28 +57,28 @@ ptAdd = Decrypt(cAdd,keys.secretKey)
 precision = 8
 precision = 8
 print("Results of homomorphic computations:")
 print("Results of homomorphic computations:")
 result = Decrypt(c1, keys.secretKey)
 result = Decrypt(c1, keys.secretKey)
-result.SetLength(batchSize)
+result.SetLength(batch_size)
 print("x1 = " + str(result))
 print("x1 = " + str(result))
 print("Estimated precision in bits: " + str(result.GetLogPrecision()))
 print("Estimated precision in bits: " + str(result.GetLogPrecision()))
 
 
 # Decrypt the result of scalar multiplication
 # Decrypt the result of scalar multiplication
-result = Decrypt(cScalar,keys.secretKey)
-result.SetLength(batchSize)
+result = Decrypt(c_scalar,keys.secretKey)
+result.SetLength(batch_size)
 print("4 * x1 = " + str(result))
 print("4 * x1 = " + str(result))
 
 
 # Decrypt the result of multiplication
 # Decrypt the result of multiplication
-result = Decrypt(cMult,keys.secretKey)
-result.SetLength(batchSize)
+result = Decrypt(c_mult,keys.secretKey)
+result.SetLength(batch_size)
 print("x1 * x2 = " + str(result))
 print("x1 * x2 = " + str(result))
 
 
 # Decrypt the result of rotations
 # Decrypt the result of rotations
-result = Decrypt(cRot1,keys.secretKey)
-result.SetLength(batchSize)
+result = Decrypt(c_rot1,keys.secretKey)
+result.SetLength(batch_size)
 print("In rotations, very small outputs (~10^-10 here) correspond to 0's:")
 print("In rotations, very small outputs (~10^-10 here) correspond to 0's:")
 print("x1 rotated by 1 = " + str(result))
 print("x1 rotated by 1 = " + str(result))
 
 
-result = Decrypt(cRot2,keys.secretKey)
-result.SetLength(batchSize)
+result = Decrypt(c_rot2,keys.secretKey)
+result.SetLength(batch_size)
 print("x1 rotated by -2 = " + str(result))
 print("x1 rotated by -2 = " + str(result))