Accesing ciphertexts elements and copying them

Hello,

I wanted to ask if OpenFHE has any method by which I can get an element of a ciphertext (still encrypted) and use it to create another ciphertext where all the elements have the same value as the one I retrieved from the original ciphertext.

Update: I was able to retrieve the element that I wanted but now I don’t know how I can create a ciphertext with that value. The way I do it is as follows:

  • I use the method GetElements() to retrieve a std::vector<DCRTPoly>;
  • From that vector, I do vector[0].GetElementAtIndex(0)[0] to get the first element of the ciphertext.

But after that, I can’t really find a way to convert that into a DCRTPoly element so that I can put it in a ciphertext. This is because the result of vector[0].GetElementAtIndex(0)[0] is an int and I can’t find any method to create a DCRTPoly element with an int.

PS: It also works if there is a way to decrypt a single int (which I can’t also find)

I don’t know if I got it right, but I’d use a mask vector (a vector with all zeros and a one in the position you want to extract) in order to extract the i-th element, then I’d rotate \log(n) times (where n is the number of slots) to repeat the value in the ciphertext.

(I assume you are working on CKKS, not sure why lol)

I forgot to mention but I’m using BFV and I’m using Coefficient Packing so that doesn’t work. If I multiply by a vector with only 0 and 1 in the i-th element, I’ll just rotate the original ciphertext by i

  1. reconsider the packing you are using so you can use masking.
  2. masking the first element as cited above, will get you a CT with the encryped element in the first slot.
  3. use EvalSum on the result. specify the batch size. the result will be the encrypted element duplicated in the first batchsize slots.

A ciphertext is NOT a DCRTPoly, it is actually two (or occasionally 3) DCRTPolys . The “GetElement” actually is just getting you the native integer of one of the towers of one of the polys, which is useless on its own.

I can’t reconsider the packing since I’m trying to compare implementations of the same algorithm with Slot Packing and Coefficient packing.

Is it possible to use DCRTPoly representation to do what I want? I never worked with it

Sorry I am not that familiar with the variations of packing, as I exclusively use our vector packing in applications. DCRTPoly is the fundamental data structure that we use internally. it contains all the coefficients of a single polynomial in RNS form i.e. each tower is a ring, and is modulo a 64bit value.
a ciphertext on the other hand has two DCRTPolys (or three if it is right after an evalmult or before relinearization. it can be in coefficient or eval form depending on if it is fresh or being used in computation (coeff is before the NTT and eval is after).

Hi @Bernardo_Ramalho

This operation can be done in Packed encoding using the logic @dcousins described. It would be hard in the CoeffPacked encoding. The only ideas that come to mind are: (1) homomorphic encoding (expensive) and (2) using extraction to LWE. This topic is similar to the discussion we had at Inverting a Coefficient Packed Ciphertext

Manipulating DCRTPOLY would not be a good idea as you need to perform these operations homorphically, as pointed out by @dcousins

Thanks a lot for the help.

I decided not to implement it using Coefficient packing and will just explain in my thesis why it is not feasible