| 86 | } |
| 87 | |
| 88 | BFVVector::plain_t BFVVector::decrypt(const shared_ptr<SecretKey>& sk) const { |
| 89 | vector<int64_t> result; |
| 90 | result.reserve(this->size()); |
| 91 | |
| 92 | for (size_t idx = 0; idx < this->_ciphertexts.size(); ++idx) { |
| 93 | vector<int64_t> partial_result; |
| 94 | |
| 95 | Plaintext plaintext; |
| 96 | this->tenseal_context()->decrypt(*sk, this->_ciphertexts[idx], |
| 97 | plaintext); |
| 98 | this->tenseal_context()->decode<BatchEncoder>(plaintext, |
| 99 | partial_result); |
| 100 | |
| 101 | // result contains all slots of ciphertext (poly_modulus_degree) |
| 102 | // we use the real vector size to delimit the resulting plaintext vector |
| 103 | auto partial_decr = |
| 104 | vector<int64_t>(partial_result.cbegin(), |
| 105 | partial_result.cbegin() + this->_sizes[idx]); |
| 106 | result.insert(result.end(), partial_decr.begin(), partial_decr.end()); |
| 107 | } |
| 108 | |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | shared_ptr<BFVVector> BFVVector::power_inplace(unsigned int power) { |
| 113 | // if the power is zero, return a new encrypted vector of ones |