# How to make a multiplication of DCRTPoly?

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)?

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.

1 Like

This unittest demonstrates how to create DCRTPoly elements and perform basic arithmetic with them.

2 Likes

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

Thanks !

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

1 Like

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.

1 Like