How to modify Plaintext coefficients in CKKS?


I want to iterate through the individual coefficients of a plaintext in its RNS form and be able to modify them at will. Basically I’m studying the impact of a bit flip in different stages of a FHE pipeline.

This can be done in a easy way? Or my choice is to overload the operator for example?

Given an vector of double (input) I can encode it and see the coefficients but can’t change them.

Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(x1);
auto plainElem = ptxt1->GetElement<DCRTPoly>().GetAllElements();
for (size_t i = 0; i < plainElem.size(); i++)
    std::cout << plainElem[i] << std::endl;

I’m sorry about the basic question about using your library.
Thank you!

ptxt1->GetElement<DCRTPoly>() can be modified directly just like any DCRTPoly. You can introduce a variable by reference to ptxt1->GetElement<DCRTPoly>() and work with it as a DCRTPoly. You can look up the API for DCRTPoly at Template Class DCRTPolyImpl — OpenFHE documentation

Thank you for your reply! I tried that and didn’t work and that’s why I made the post.

Of course was my error… For example changing to zero the first coefficient of each polynomial, I was doing:

    Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(x1);
    DCRTPoly plainElem = ptxt1->GetElement<DCRTPoly>();
    auto elems =  plainElem.GetAllElements();

    std::cout << elems.size() << std::endl;
    for (size_t i = 0; i < elems.size(); i++)
        elems[i][0] = 0;

Insted of

    for (size_t i = 0; i < elems.size(); i++)
        plainElem.GetAllElements()[i][0] = 0;

Thank you again!