I modified a tutorial example as follows:
int main() {
CCParams<CryptoContextBGVRNS> parameters;
parameters.SetMultiplicativeDepth(2);
parameters.SetPlaintextModulus(65537);
CryptoContext<DCRTPoly> cryptoContext = GenCryptoContext(parameters);
cryptoContext->Enable(PKE);
cryptoContext->Enable(KEYSWITCH);
cryptoContext->Enable(LEVELEDSHE);
KeyPair<DCRTPoly> keyPair;
keyPair = cryptoContext->KeyGen();
cryptoContext->EvalMultKeyGen(keyPair.secretKey);
cryptoContext->EvalRotateKeyGen(keyPair.secretKey, {1, 2, -1, -2});
std::vector<int64_t> vectorOfInts1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Plaintext plaintext1 = cryptoContext->MakePackedPlaintext(vectorOfInts1);
std::vector<int64_t> vectorOfInts2 = {3, 2, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Plaintext plaintext2 = cryptoContext->MakePackedPlaintext(vectorOfInts2);
auto ciphertext1 = cryptoContext->Encrypt(keyPair.publicKey, plaintext1);
auto ciphertext2 = cryptoContext->Encrypt(keyPair.publicKey, plaintext2);
std::cout << "Plaintext #1: " << plaintext1 << std::endl;
std::cout << "Plaintext #2: " << plaintext2 << std::endl;
std::cout << "\nResults of homomorphic computations" << std::endl;
// auto ciphertextActual = test_binops(cryptoContext, ciphertext1, ciphertext2);
auto v0 = cryptoContext;
auto v1 = ciphertext1;
auto v2 = ciphertext2;
auto v3 = v0->EvalAdd(v1, v2);
auto v4 = v0->EvalSub(v1, v2);
auto v5 = v0->EvalMult(v3, v4);
auto ciphertextActual = v5;
Plaintext plaintextActual;
cryptoContext->Decrypt(keyPair.secretKey, ciphertextActual, &plaintextActual);
std::cout << "output without GetPackedValue: " << plaintextActual << std::endl;
auto actual = plaintextActual->GetPackedValue();
std::cout << "output with GetPackedValue: " << actual << std::endl;
return 0;
}
The output is
output without GetPackedValue: ( -8 0 8 ... )
output with GetPackedValue: [ -8 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 <many more zeroes follow> ]
Is there an API or utility function in OpenFHE that preserves the size of the input vector when decrypting the resulting output?
I can just std::vector::resize
the result, but I wonder if I’m just missing that somewhere in the existing API.