SEAL-Python
SEAL-Python copied to clipboard
How to get the coefficient of ciphertext?
I tried using the original SEAL library, which defines a data() function in the Ciphertext class that returns the coefficients of the ciphertext. However, I saw in "wrapper.cpp" that SEAL-Python does not seem to include this function.
// ciphertext.h
py::class_<Ciphertext>(m, "Ciphertext")
.def(py::init<>())
.def(py::init<const SEALContext &>())
.def(py::init<const SEALContext &, parms_id_type>())
.def(py::init<const SEALContext &, parms_id_type, std::size_t>())
.def(py::init<const Ciphertext &>())
.def("coeff_modulus_size", &Ciphertext::coeff_modulus_size)
.def("poly_modulus_degree", &Ciphertext::poly_modulus_degree)
.def("size", &Ciphertext::size)
.def("size_capacity", &Ciphertext::size_capacity)
.def("is_transparent", &Ciphertext::is_transparent)
.def("is_ntt_form", py::overload_cast<>(&Ciphertext::is_ntt_form, py::const_))
.def("parms_id", py::overload_cast<>(&Ciphertext::parms_id, py::const_))
.def("scale", py::overload_cast<>(&Ciphertext::scale, py::const_))
.def("scale", [](Ciphertext &cipher, double scale){
cipher.scale() = scale;
})
.def("save", [](const Ciphertext &cipher, const std::string &path){
std::ofstream out(path, std::ios::binary);
cipher.save(out);
out.close();
})
.def("load", [](Ciphertext &cipher, const SEALContext &context, const std::string &path){
std::ifstream in(path, std::ios::binary);
cipher.load(context, in);
in.close();
})
.def("save_size", [](const Ciphertext &cipher){
return cipher.save_size();
})
.def("to_string", [](const Ciphertext &cipher){
std::stringstream out(std::ios::binary | std::ios::out);
cipher.save(out);
return py::bytes(out.str());
});