Browse Source

Merge pull request #6 from openfheorg/Oliveira_rotations

binding rotations + rotate keygen
Rener Oliveira 2 years ago
parent
commit
ec245bcfe1
2 changed files with 7 additions and 1 deletions
  1. 4 1
      src/bindings.cpp
  2. 3 0
      src/pke/examples/simple-integers.py

+ 4 - 1
src/bindings.cpp

@@ -31,8 +31,11 @@ void bind_crypto_context(py::module &m){
             .def("Enable",static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), "Enable a feature for the CryptoContext")
             .def("Enable",static_cast<void (CryptoContextImpl<DCRTPoly>::*)(PKESchemeFeature)>(&CryptoContextImpl<DCRTPoly>::Enable), "Enable a feature for the CryptoContext")
             .def("KeyGen",&CryptoContextImpl<DCRTPoly>::KeyGen,"Generate a key pair with public and private keys") 
             .def("KeyGen",&CryptoContextImpl<DCRTPoly>::KeyGen,"Generate a key pair with public and private keys") 
             .def("EvalMultKeyGen",&CryptoContextImpl<DCRTPoly>::EvalMultKeyGen,"Generate the evaluation key for multiplication")
             .def("EvalMultKeyGen",&CryptoContextImpl<DCRTPoly>::EvalMultKeyGen,"Generate the evaluation key for multiplication")
+            .def("EvalRotateKeyGen",&CryptoContextImpl<DCRTPoly>::EvalRotateKeyGen,"Generate the evaluation key for rotation",
+            py::arg("privateKey"),py::arg("indexList"),py::arg("publicKey")=nullptr)
             .def("MakePackedPlaintext",&CryptoContextImpl<DCRTPoly>::MakePackedPlaintext,"Make a plaintext from a vector of integers",
             .def("MakePackedPlaintext",&CryptoContextImpl<DCRTPoly>::MakePackedPlaintext,"Make a plaintext from a vector of integers",
-            py::arg("value"),py::arg("depth")=1,py::arg("level")=0);
+            py::arg("value"),py::arg("depth")=1,py::arg("level")=0)
+            .def("EvalRotate",&CryptoContextImpl<DCRTPoly>::EvalRotate,"Rotate a ciphertext");
             //.def("MakePackedPlaintext",static_cast<Plaintext (CryptoContextImpl<DCRTPoly>::*)(const std::vector<int64_t>&)>(&CryptoContextImpl<DCRTPoly>::MakePackedPlaintext), "Make a plaintext from a vector of integers")
             //.def("MakePackedPlaintext",static_cast<Plaintext (CryptoContextImpl<DCRTPoly>::*)(const std::vector<int64_t>&)>(&CryptoContextImpl<DCRTPoly>::MakePackedPlaintext), "Make a plaintext from a vector of integers")
     // Generator Functions    
     // Generator Functions    
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);
     m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>);

+ 3 - 0
src/pke/examples/simple-integers.py

@@ -29,6 +29,7 @@ keypair = cryptoContext.KeyGen()
 print("Public Key: " + str(keypair.publicKey))
 print("Public Key: " + str(keypair.publicKey))
 
 
 cryptoContext.EvalMultKeyGen(keypair.secretKey)
 cryptoContext.EvalMultKeyGen(keypair.secretKey)
+cryptoContext.EvalRotateKeyGen(keypair.secretKey, [1, 2, -1, -2]);
 
 
 vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 vectorOfInts1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 vectorOfInts2 = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]
@@ -38,3 +39,5 @@ plaintext2 = cryptoContext.MakePackedPlaintext(vectorOfInts2)
 plaintext3 = cryptoContext.MakePackedPlaintext(vectorOfInts3)
 plaintext3 = cryptoContext.MakePackedPlaintext(vectorOfInts3)
 
 
 
 
+ciphertext1 = Ciphertext()
+ciphertextRot1 = cryptoContext.EvalRotate(ciphertext1, 1)