Can we add new elements to an encrypted vector?


I try to add new elements to an encrypted vector. For example, I have a vector E(1,2,3). Then, I want to add new elements as a vector E(4,5) and I will get a vector E(1,2,3,4,5) as a result. Is there a way to perform this operation using OpenFHE? Thank you for your time.

Hi there! What’s your end-goal with this? You can’t “append” elements in that sense but you can do the following (pseudocode)

a = Enc([1,2,3,0,0,...,0])
b = Enc([0,0,0,4,5,...,0])
c = a + b

to follow upon @iquah … generally when you encrypt a vector, even though you only provide a few elements the rest of the ciphertext slots (= ringsize for B*V and ringsize/2 for CKKS) are set to zero.
when you decrypt you get ALL the slots back. In general you need to keep and manage your actual vector size in your application code.

Note this impacts rotation as well. Rotation is done on the entire length vector.

1 Like