# CKKS: Plaintext from EVAL to COEFF

**URL:** <https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954>\
**Category:** Library Questions\
**Created:** [December 6, 2023, 2:09pm UTC](https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954 "2023-12-06T14:09:57Z")\
**Posts on this page:** 4\
**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:** [December 6, 2023, 2:09pm UTC](https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954/1 "2023-12-06T14:09:57Z")

</div>

Hello,  
For academic propose I’m testing a few things and one of them is changing a encoded data from COEFF space.  
I’m 90% sure that what I’m doing is correct, but I need 100%.  
So If I want to change the j coeff of a plaintext I do this:

```auto
Initialization
input
etc
.
.
.
Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(input);
ptxt1->GetElement<DCRTPoly>().SwitchFormat();
auto originalCoeff = ptxt1->GetElement<DCRTPoly>().GetAllElements()[0][j];
ptxt1->GetElement<DCRTPoly>().GetAllElements()[0][j] = changeCoeff(originalCoeff);
ptxt1->GetElement<DCRTPoly>().SwitchFormat();

```

Need to be sure that:

1. ptxt1 is in deed the encoding of the input data
2. The format of ptxt1-\>GetElement().GetAllElements()[0] is in EVAL space
3. When i make ptxt1-\>GetElement().SwitchFormat() all the elements that I will receive with ptxt1-\>GetElement().GetAllElements()[0] are in deed now in COEFF space

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [December 6, 2023, 6:24pm UTC](https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954/2 "2023-12-06T18:24:16Z")

</div>

It would be more helpful if you could provide additional information about your objective.

For the code you provided above, I can confirm the following:  
`ptxt1` after encoding will be in EVAL mode (evaluation representation of the RNS polynomials).  
When you call `ptxt1->GetElement<DCRTPoly>().SwitchFormat();`, the representation of `ptxt1` RNS polynomials will become COEFF mode (coefficient representation of the RNS polynomials).  
You seem to be only updating the `j`-th coefficient of the first RNS polynomial, which does not make sense to me.

Note that CKKS encoding invokes a special form of Discrete Fourier Transform to represent the input message (`input` in your example) as a polynomial. To me, the input message is treated as one unit and I do not think you can change one part of it that way, unless your input message includes only a single value.

Btw, you can print out the plaintext DCRT element and see check its representation as follows:  
`std::cout << ptxt1->GetElement<DCRTPoly>();`

---

<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:** [December 7, 2023, 3:06pm UTC](https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954/3 "2023-12-07T15:06:20Z")

</div>

Perfect! I’m doing a resilience analysis of the CKKS scheme when a bit flip occurs in different stages of the pipeline. Because of what you say of NTT always breaks…

When we encode/encrypt some input, OpenFHE saves only the data in DCRTPoly? Or it also saves the NativePoly or extra info?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [December 7, 2023, 3:51pm UTC](https://openfhe.discourse.group/t/ckks-plaintext-from-eval-to-coeff/954/4 "2023-12-07T15:51:48Z")

</div>

Only DCRTPoly is used after encode/encrypt.
