# How to make a multiplication of DCRTPoly?

**URL:** https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698
**Category:** Library Questions
**Created:** [July 13, 2023, 2:35pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698 "2023-07-13T14:35:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Justine\_P](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Justine\_P](https://openfhe.discourse.group/u/Justine_P)
#### Post date: [July 13, 2023, 2:35pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/1 "2023-07-13T14:35:02Z")

</div>

I’m working on an implementation of multiparty BGV and BFV and I need to multiply two DCRTPoly.

I already use the normal multiplication on it but when I try to take a look at the corresponding integer it doesn’t work.

For exemple, DCRTPoly(1) \* DCRTPoly(1) != DCRTPoly(1), because it’s a term by term multiplication.  
The multiplication by an integer works.

So the question is : How to compute DCRTPoly (A \* B) by using DCRTPoly(A) and DCRTPoly(B)?

---

<div class="post-metadata">

### Author: ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)
#### Post date: [July 13, 2023, 3:01pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/2 "2023-07-13T15:01:15Z")

</div>

Can you please list what result you are getting?

Expected: `DCRTPoly(1) * DCRTPoly(1) != DCRTPoly(1)`

Actual: `TODO`

* * *

> because it’s a term by term multiplication.

element-wise multiplication is expected.

---

<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: [July 13, 2023, 3:43pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/3 "2023-07-13T15:43:29Z")

</div>

This [unittest](https://github.com/openfheorg/openfhe-development/blob/v1.0.4/src/core/unittest/UnitTestDCRTElements.cpp#L286) demonstrates how to create DCRTPoly elements and perform basic arithmetic with them.

---

<div class="post-metadata">

### Author: ![Justine\_P](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Justine\_P](https://openfhe.discourse.group/u/Justine_P)
#### Post date: [July 17, 2023, 12:15pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/4 "2023-07-17T12:15:37Z")

</div>

Finally I find the solution, by searching in the decryption function of my cryptosystem. I need to decode the multiplication.

Thanks !

---

<div class="post-metadata">

### Author: ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)
#### Post date: [July 17, 2023, 2:25pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/5 "2023-07-17T14:25:08Z")

</div>

Hmm, can you elaborate on this? How was the decryption causing the issue you were running into? Just so I know how to best help other people in the future

---

<div class="post-metadata">

### Author: ![Justine\_P](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Justine\_P](https://openfhe.discourse.group/u/Justine_P)
#### Post date: [July 17, 2023, 3:09pm UTC](https://openfhe.discourse.group/t/how-to-make-a-multiplication-of-dcrtpoly/698/6 "2023-07-17T15:09:30Z")

</div>

The idea is when you multiply two DCRTPoly, you’re doing it term by term.

For example the first element of the DCRTPoly corresponding to the Plaintext “1” is 148 (multiplicative depth = 3 and the scheme is BGV).  
When you multiply this DCRT by itself the result is 21904=148^2 % modulus[0] (here modulus[0] = 2148728833). Here we expect the result to be 148 (because 1 \* 1 = 1).

I precise that i’m working with packed Plaintext and I’m working on pure multiparty BGV and BFV.  
So I need to use the bit Decomposition and I want to try to construct again the DCRTPoly (need this part to build the Relinearisation key).  
If you want to compute BitDecomp(DCRTPoly(a)) by PowersofTwo(DCRTPoly(b)) ( expecting result = a\*b), you can’t have the good result if you don’t decode it. In fact, this result is correct but you need to work a little more on it to see it clearly.

If you take a look at the decryption function (because the multCore function only does ct1[i] \* ct2[j] classical multiplication), you can find how to decode your DCRTPoly. DecryptCore makes the decryption (used in Decrypt). Decrypt puts the DCRTPoly in the NativePoly (in a new Plaintext) and decode by using the scaling factor and the Decode function. So you need to keep the good scaling factor to decode it correctly.
