# How to modify Plaintext coefficients in CKKS?

**URL:** <https://openfhe.discourse.group/t/how-to-modify-plaintext-coefficients-in-ckks/822>\
**Category:** Library Questions\
**Created:** [September 22, 2023, 3:45pm UTC](https://openfhe.discourse.group/t/how-to-modify-plaintext-coefficients-in-ckks/822 "2023-09-22T15:45:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmazz](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@mmazz](https://openfhe.discourse.group/u/mmazz)\
**Post date:** [September 22, 2023, 3:45pm UTC](https://openfhe.discourse.group/t/how-to-modify-plaintext-coefficients-in-ckks/822/1 "2023-09-22T15:45:43Z")

</div>

Hello!

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!

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [September 22, 2023, 9:27pm UTC](https://openfhe.discourse.group/t/how-to-modify-plaintext-coefficients-in-ckks/822/2 "2023-09-22T21:27:17Z")

</div>

`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](https://openfhe-development.readthedocs.io/en/latest/api/classlbcrypto_1_1DCRTPolyImpl.html?highlight=DCRTPolyImpl)

---

<div class="post-metadata">

**Author:** ![mmazz](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@mmazz](https://openfhe.discourse.group/u/mmazz)\
**Post date:** [September 29, 2023, 6:47pm UTC](https://openfhe.discourse.group/t/how-to-modify-plaintext-coefficients-in-ckks/822/3 "2023-09-29T18:47:19Z")

</div>

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:

```auto
    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

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

```

Thank you again!
