# NTT operations in CKKS

**URL:** <https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066>\
**Category:** Library Questions\
**Created:** [February 5, 2024, 9:09pm UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066 "2024-02-05T21:09:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuperMusey](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@SuperMusey](https://openfhe.discourse.group/u/SuperMusey)\
**Post date:** [February 5, 2024, 9:09pm UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066/1 "2024-02-05T21:09:05Z")

</div>

Hi,

I am new to OpenFHE, and am trying to understand the use of NTT(CRT).

According to my understanding, the ciphertext polynomial ring elements are either in COEF form or EVAL form. When operations like EvalAdd() are done, the ciphertext is transformed to EVAL form by applying NTT(CRT), the operations are done, and then converted back to COEF. I might be wrong.

When I print the ciphertext to stdout, I get an output of form:

```auto
Element 0: 0: EVAL: [vector of numbers] modulus: number
1: EVAL: [vector of numbers] modulus: number
.
.
.
Element 1: 0: EVAL: [vector of numbers] modulus: number
1: EVAL: [vector of numbers] modulus: number
.
.
.

```

So is this output in EVAL form (The form of the polynomial ring elements after NTT is applied)? Can I switch the form of the ciphertext (I know there is a SwitchFormat() function) to print the other form? Or are NTT operations separate from operations like EvalAdd()? I basically want to print the output of NTT operations on ciphertexts

---

<div class="post-metadata">

**Author:** ![dcousins](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/dcousins/32/71_2.png) [@dcousins](https://openfhe.discourse.group/u/dcousins)\
**Post date:** [February 6, 2024, 2:55pm UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066/2 "2024-02-06T14:55:08Z")

</div>

IIRC in OpenFHE, we usually keep all ciphertext keys etc in Eval form. the only time we go back to Coef form is for decryption or rotation operations. otherwise we would be going back and forth all the time and that is not efficient.

the switchformat function will basically convert between the two forms. I believe you can also get the current setting of the format to check what format your ciphertext is in.

If you have a signals background you can think of NTT as an FFT: coef is the time domain, and eval is the frequency domain. we have NTT and inverse NTT. to go back and forth.  
To simply things, you might want to set the problem up so you have no multiplicative depth. that will give you a small number of residues.

---

<div class="post-metadata">

**Author:** ![SuperMusey](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@SuperMusey](https://openfhe.discourse.group/u/SuperMusey)\
**Post date:** [February 12, 2024, 9:04pm UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066/3 "2024-02-12T21:04:23Z")

</div>

That makes sense. While I was digging into the NTT implementation, I found that a rootOfUnity table was used in many places, and from other posts, it seems to be the precomputed powers of a 2N-th root of unity modulo q. Is it possible to see the contents of the table (maybe by displaying it somewhere)?

---

<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:** [February 16, 2024, 12:08am UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066/4 "2024-02-16T00:08:07Z")

</div>

Yes, it is a static map that you can print out in your C++ code. See `m_rootOfUnityReverseTableByModulus` in [Program Listing for File transformnat.h — OpenFHE documentation](https://openfhe-development.readthedocs.io/en/latest/api/program_listing_file_core_include_math_hal_intnat_transformnat.h.html?highlight=m_rootOfUnityReverseTableByModulus) The class is accessed as `ChineseRemainderTransformFTT<NativeVector>` in upper layers of OpenFHE. So you should be able to access `ChineseRemainderTransformFTT<NativeVector>::m_rootOfUnityReverseTableByModulus`. Note that we use bit-reversed NTT

---

<div class="post-metadata">

**Author:** ![SuperMusey](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@SuperMusey](https://openfhe.discourse.group/u/SuperMusey)\
**Post date:** [March 30, 2024, 8:39pm UTC](https://openfhe.discourse.group/t/ntt-operations-in-ckks/1066/5 "2024-03-30T20:39:02Z")

</div>

Thank you! This worked
