# Automaticly find a good Plaintext Modulus

**URL:** <https://openfhe.discourse.group/t/automaticly-find-a-good-plaintext-modulus/312>\
**Category:** Library Questions\
**Tags:** questions, openfhe-help\
**Created:** [January 23, 2023, 10:26am UTC](https://openfhe.discourse.group/t/automaticly-find-a-good-plaintext-modulus/312 "2023-01-23T10:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![smerte](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/smerte/32/83_2.png) [@smerte](https://openfhe.discourse.group/u/smerte)\
**Post date:** [January 23, 2023, 10:26am UTC](https://openfhe.discourse.group/t/automaticly-find-a-good-plaintext-modulus/312/1 "2023-01-23T10:26:16Z")

</div>

Currently, I am manually calculating or using the method below to find a plaintext modulus that is vaild and big enough for my needs (e.g., for chosen multiplicative depth).

```auto
FirstPrime(uint64_t nBits, uint64_t m);

```

By valid I mean a primeModulus(q) and a cyclotomic number(m) satisfying the condition: (q-1)/m is an integer.

Are there alternative ways for doing this?

---

<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:** [January 25, 2023, 10:19pm UTC](https://openfhe.discourse.group/t/automaticly-find-a-good-plaintext-modulus/312/2 "2023-01-25T22:19:33Z")

</div>

No, this is the recommended approach. The plaintext modulus depends on the application. At a high level, the plaintext modulus should be large enough not to cause a wrap-around for the worst case of user application. I recommend watching [Homomorphic Encryption for OpenFHE Users – OpenFHE.org](https://www.openfhe.org/portfolio-item/homomorphic-encryption-for-palisade-users-3/) for more details. Slide 15 is the one that describes the logic.

For _m_, you can use 131,072 to make sure it is compatible with any ring dimension.
