Browse Source

erasing old dec wrapper + refactoring examples

Rener Oliveira (Ubuntu WSL) 1 year ago
parent
commit
748bce12a4

+ 0 - 1
CMakeLists.txt

@@ -44,7 +44,6 @@ pybind11_add_module(openfhe
                     src/bindings.cpp 
                     src/binfhe_bindings.cpp
                     src/binfhe/binfhecontext_wrapper.cpp
-                    src/pke/decryption.cpp 
                     src/pke/serialization.cpp 
                     src/pke/cryptocontext_wrapper.cpp
                     )

+ 0 - 1
include/bindings.h

@@ -9,7 +9,6 @@ void bind_enums_and_constants(pybind11::module &m);
 void bind_keys(pybind11::module &m);
 void bind_encodings(pybind11::module &m);
 void bind_ciphertext(pybind11::module &m);
-void bind_decryption(pybind11::module &m);
 void bind_serialization(pybind11::module &m);
 void bind_schemes(pybind11::module &m);
 #endif // OPENFHE_BINDINGS_H

+ 0 - 1
src/bindings.cpp

@@ -315,7 +315,6 @@ PYBIND11_MODULE(openfhe, m)
     bind_keys(m);
     bind_encodings(m);
     bind_ciphertext(m);
-    bind_decryption(m);
     bind_serialization(m);
     bind_schemes(m);
     // binfhe library

+ 0 - 18
src/pke/decryption.cpp

@@ -1,18 +0,0 @@
-#include <pybind11/pybind11.h>
-#include <pybind11/stl.h>
-#include "openfhe.h"
-#include "bindings.h"
-
-using namespace lbcrypto;
-namespace py = pybind11;
-
-template<typename Element>
-Plaintext DecryptWrapper_standalone(Ciphertext<Element> ciphertext,const PrivateKey<Element> privateKey){
-    Plaintext plaintextDecResult;
-    auto cc = ciphertext->GetCryptoContext();
-    cc->Decrypt(privateKey, ciphertext,&plaintextDecResult);
-    return plaintextDecResult;
-}
-void bind_decryption(py::module &m){
-    m.def("Decrypt",&DecryptWrapper_standalone<DCRTPoly>,"Decrypt a ciphertext using private key");
-}

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

@@ -49,7 +49,7 @@ def automatic_rescale_demo(scal_tech):
     c18 = cc.EvalMult(c16, c2)                   # x^18
     cRes = cc.EvalAdd(cc.EvalAdd(c18, c9), 1.0)  # Final result
 
-    result = Decrypt(cRes,keys.secretKey)
+    result = cc.Decrypt(cRes,keys.secretKey)
     print("x^18 + x^9 + 1 = ", result)
     result.SetLength(batch_size)
     print(f"Result: {result}")
@@ -112,7 +112,7 @@ def manual_rescale_demo(scal_tech):
     cRes_depth2 = cc.EvalAdd(cc.EvalAdd(c18_depth2, c9_depth2), 1.0)
     cRes_depth1 = cc.Rescale(cRes_depth2)
 
-    result = Decrypt(cRes_depth1,keys.secretKey)
+    result = cc.Decrypt(cRes_depth1,keys.secretKey)
     result.SetLength(batch_size)
     print("x^18 + x^9 + 1 = ", result)
 
@@ -153,7 +153,7 @@ def hybrid_key_switching_demo1():
     c_rot2 = cc.EvalRotate(c_rot1,-2)
     time2digits = time.time() - t
 
-    result = Decrypt(c_rot2,keys.secretKey)
+    result = cc.Decrypt(c_rot2,keys.secretKey)
     result.SetLength(batch_size)
     print(f"x rotate by -1 = {result}")
     print(f" - 2 rotations with HYBRID (2 digits) took {time2digits*1000} ms")
@@ -198,7 +198,7 @@ def hybrid_key_switching_demo2():
     time3digits = time.time() - t
     # The runtime here is smaller than the previous demo
 
-    result = Decrypt(c_rot2,keys.secretKey)
+    result = cc.Decrypt(c_rot2,keys.secretKey)
     result.SetLength(batch_size)
     print(f"x rotate by -1 = {result}")
     print(f" - 2 rotations with HYBRID (3 digits) took {time3digits*1000} ms")
@@ -263,13 +263,13 @@ def fast_rotation_demo1():
 
     c_res_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
     
-    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result = cc.Decrypt(c_res_no_hoist,keys.secretKey)
     result.SetLength(batch_size)
     print(f"Result without hoisting: {result}")
     print(f" - 7 rotations without hoisting took {time_no_hoisting*1000} ms")
 
     
-    result = Decrypt(c_res_hoist,keys.secretKey)
+    result = cc.Decrypt(c_res_hoist,keys.secretKey)
     result.SetLength(batch_size)
     print(f"Result with hoisting: {result}")
     print(f" - 7 rotations with hoisting took {time_hoisting*1000} ms")
@@ -349,12 +349,12 @@ def fast_rotation_demo2():
 
     c_res_hoist = c + c_rot1 + c_rot2 + c_rot3 + c_rot4 + c_rot5 + c_rot6 + c_rot7
 
-    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result = cc.Decrypt(c_res_no_hoist,keys.secretKey)
     result.SetLength(batch_size)
     print(f"Result without hoisting: {result}")
     print(f" - 7 rotations without hoisting took {time_no_hoisting*1000} ms")
 
-    result = Decrypt(c_res_no_hoist,keys.secretKey)
+    result = cc.Decrypt(c_res_no_hoist,keys.secretKey)
     result.SetLength(batch_size)
     print(f"Result with hoisting: {result}")
     print(f" - 7 rotations with hoisting took {time_hoisting*1000} ms")

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

@@ -39,7 +39,7 @@ def eval_logistic_example():
     upper_bound = 4
     result = cc.EvalLogistic(ciphertext, lower_bound, upper_bound, poly_degree)
 
-    plaintext_dec = Decrypt(result, key_pair.secretKey)
+    plaintext_dec = cc.Decrypt(result, key_pair.secretKey)
     plaintext_dec.SetLength(encoded_length)
 
     expected_output = [0.0179885, 0.0474289, 0.119205, 0.268936, 0.5, 0.731064, 0.880795, 0.952571, 0.982011]
@@ -82,7 +82,7 @@ def eval_function_example():
     upper_bound = 9
     result = cc.EvalChebyshevFunction(math.sqrt,ciphertext, lower_bound, upper_bound, poly_degree)
 
-    plaintext_dec = Decrypt(result, key_pair.secretKey)
+    plaintext_dec = cc.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]

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

@@ -87,7 +87,7 @@ def iterative_bootstrap_example():
     # Step 5: Measure the precision of a single bootstrapping operation.
     ciphertext_after = cryptocontext.EvalBootstrap(ciph)
 
-    result = Decrypt(ciphertext_after,key_pair.secretKey)
+    result = cryptocontext.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,key_pair.secretKey)
+    result_two_iterations = cryptocontext.Decrypt(ciphertext_two_iterations,key_pair.secretKey)
     result_two_iterations.SetLength(num_slots)
     actual_result = result_two_iterations.GetCKKSPackedValue()
 

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

@@ -39,11 +39,11 @@ def main():
     result2 = cc.EvalPoly(ciphertext1, coefficients2)
     time_eval_poly2 = time.time() - t
 
-    plaintext_dec = Decrypt(result, key_pair.secretKey)
+    plaintext_dec = cc.Decrypt(result, key_pair.secretKey)
 
     plaintext_dec.SetLength(encoded_length)
 
-    plaintext_dec2 = Decrypt(result2, key_pair.secretKey)
+    plaintext_dec2 = cc.Decrypt(result2, key_pair.secretKey)
 
     plaintext_dec2.SetLength(encoded_length)
 

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

@@ -64,7 +64,7 @@ def simple_bootstrap_example():
 
     print(f"Number of levels remaining after bootstrapping: {ciphertext_after.GetLevel()}")
 
-    result = Decrypt(ciphertext_after,key_pair.secretKey)
+    result = cryptocontext.Decrypt(ciphertext_after,key_pair.secretKey)
     result.SetLength(encoded_length)
     print(f"Output after bootstrapping: {result}")
 

+ 6 - 6
src/pke/examples/simple-integers-bgvrns.py

@@ -63,16 +63,16 @@ ciphertext_rot4 = crypto_context.EvalRotate(ciphertext1, -2)
 # Sample Program: Step 5: Decryption
 
 # Decrypt the result of additions
-plaintext_add_result = Decrypt(ciphertext_add_result,key_pair.secretKey)
+plaintext_add_result = crypto_context.Decrypt(ciphertext_add_result,key_pair.secretKey)
 
 # Decrypt the result of multiplications
-plaintext_mult_result = Decrypt(ciphertext_mult_result,key_pair.secretKey)
+plaintext_mult_result = crypto_context.Decrypt(ciphertext_mult_result,key_pair.secretKey)
 
 # Decrypt the result of rotations
-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 = crypto_context.Decrypt(ciphertext_rot1,key_pair.secretKey)
+plaintextRot2 = crypto_context.Decrypt(ciphertext_rot2,key_pair.secretKey)
+plaintextRot3 = crypto_context.Decrypt(ciphertext_rot3,key_pair.secretKey)
+plaintextRot4 = crypto_context.Decrypt(ciphertext_rot4,key_pair.secretKey)
 
 
 plaintextRot1.SetLength(len(vector_of_ints1))

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

@@ -63,16 +63,16 @@ ciphertext_rot4 = crypto_context.EvalRotate(ciphertext1, -2)
 # Sample Program: Step 5: Decryption
 
 # Decrypt the result of additions
-plaintext_add_result = Decrypt(ciphertext_add_result,key_pair.secretKey)
+plaintext_add_result = crypto_context.Decrypt(ciphertext_add_result,key_pair.secretKey)
 
 # Decrypt the result of multiplications
-plaintext_mult_result = Decrypt(ciphertext_mult_result,key_pair.secretKey)
+plaintext_mult_result = crypto_context.Decrypt(ciphertext_mult_result,key_pair.secretKey)
 
 # Decrypt the result of rotations
-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 = crypto_context.Decrypt(ciphertext_rot1,key_pair.secretKey)
+plaintextRot2 = crypto_context.Decrypt(ciphertext_rot2,key_pair.secretKey)
+plaintextRot3 = crypto_context.Decrypt(ciphertext_rot3,key_pair.secretKey)
+plaintextRot4 = crypto_context.Decrypt(ciphertext_rot4,key_pair.secretKey)
 
 
 plaintextRot1.SetLength(len(vector_of_ints1))