Skip to content

Commit

Permalink
Encode/Encrypt a single double (#212)
Browse files Browse the repository at this point in the history
* feature: encode/encrypt a single double

* use new encrypt method

Co-authored-by: Bogdan Cebere <bogdan.cebere@gmail.com>
  • Loading branch information
youben11 and bcebere authored Jan 16, 2021
1 parent 0793e22 commit 376914a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tenseal/cpp/tensors/ckkstensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ CKKSTensor::CKKSTensor(const shared_ptr<TenSEALContext>& ctx,

} else {
for (auto it = tensor.cbegin(); it != tensor.cend(); it++)
enc_data.push_back(CKKSTensor::encrypt(ctx, this->_init_scale,
vector<double>({*it})));
enc_data.push_back(
CKKSTensor::encrypt(ctx, this->_init_scale, *it));
}

_data = TensorStorage<Ciphertext>(enc_data, enc_shape);
Expand Down Expand Up @@ -82,6 +82,16 @@ Ciphertext CKKSTensor::encrypt(const shared_ptr<TenSEALContext>& ctx,
return ciphertext;
}

Ciphertext CKKSTensor::encrypt(const shared_ptr<TenSEALContext>& ctx,
const double scale, const double data) {
Ciphertext ciphertext(*ctx->seal_context());
Plaintext plaintext;
ctx->encode<CKKSEncoder>(data, plaintext, scale);
ctx->encrypt(plaintext, ciphertext);

return ciphertext;
}

PlainTensor<double> CKKSTensor::decrypt(const shared_ptr<SecretKey>& sk) const {
Plaintext plaintext;
auto sz = this->_data.flat_size();
Expand Down

0 comments on commit 376914a

Please sign in to comment.