# Ciphertext Modulus Calculation

**URL:** <https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646>\
**Category:** Library Questions\
**Created:** [June 20, 2023, 11:06am UTC](https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646 "2023-06-20T11:06:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)\
**Post date:** [June 20, 2023, 11:06am UTC](https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646/1 "2023-06-20T11:06:30Z")

</div>

Hello,

So I’m exploring various parameters for my thesis and can’t understand where and how OpenFHE calculates and chooses the ciphertext modulus.

So I would like to ask some questions:

- How does OpenFHE calculate the ciphertext modulus based on the parameters I select (plaintext modulus, multiplicative depth, and ring dimension)?
- Where in the library can I find the code where this happens?
- How can I print the value of the ciphertext modulus?

Thanks in advance 🙂

---

<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:** [June 20, 2023, 3:39pm UTC](https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646/2 "2023-06-20T15:39:47Z")

</div>

1. Moduli choice in OpenFHE is fairly complicated, you would need to provide further details such as which scheme you are using. Check this [paper](https://eprint.iacr.org/2020/1118.pdf) (Algorithms 1-3) for some details.

2. Depending on the scheme used, here is a pointer to the [function](https://github.com/openfheorg/openfhe-development/blob/v1.0.3/src/pke/lib/scheme/bfvrns/bfvrns-parametergeneration.cpp#L45) that is used to initialize BFV parameters.

3. You can refer to this [thread](https://openfhe.discourse.group/t/openfhe-ckks-chooses-modulus-chain-that-doesnt-guarantee-128-bits-of-security/405) to learn how to print out the ciphertext/public-key moduli.

---

<div class="post-metadata">

**Author:** ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)\
**Post date:** [June 20, 2023, 3:43pm UTC](https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646/3 "2023-06-20T15:43:06Z")

</div>

Hey, sorry for not specifying the scheme. I’m using BGV.

---

<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:** [June 20, 2023, 5:47pm UTC](https://openfhe.discourse.group/t/ciphertext-modulus-calculation/646/4 "2023-06-20T17:47:04Z")

</div>

For BGV, you can study this [function](https://github.com/openfheorg/openfhe-development/blob/v1.0.3/src/pke/lib/scheme/bgvrns/bgvrns-parametergeneration.cpp#L326).
