# CKKS - vector rotation and padding?

Hi all,

I’m trying to understand how the rotation operation interacts with the padding present in a vector x.
Say the slot-size determined by your CKKS parameters is much larger than the size of x, then x will have a lot of (zero-)padding. If I then rotate the vector by 1, how do I deal with the zero-padding in between my vector elements?

So for example, if my vector is {1, 2, 3, 4},
its representation will be {1, 2, 3, 4, 0, 0, …},
after one rotation it will be {2, 3, 4, 0, 0, …, 1},
whereas I want it to be {2, 3, 4, 1, 0, 0, …}

I could duplicate the vector x (ie. {1, 2, 3, 4, 1, 2, 3, 4}), such that I can rotate (in this case) 4 times and have the rotation of the vector at the start of my representation, before the padding? Is there a better way to do this?

Let me know if I’ve misunderstood anything about the padding, slot-size, or rotation. I’m pretty new to the OpenFHE library!

Cheers,
Lena

What is your desired functionality? If you want to rotate {1,2,3,4,-,-,-,-,…} by 1 and get {2,3,4,1,-,-,-,-,…} then yes, you need to repeat the vector inside your plaintext/ciphertext. If you can encode your vector already as {1,2,3,4,1,2,3,4,…}, then there is no additional overhead. If the ciphertext is already given to you as {1,2,3,4,0,0,0,0,…}, you need to homomorphically apply repeated rotations and summations to obtain a ciphertext encrypting {1,2,3,4,1,2,3,4,…}. Finally, if you want to obtain {2,3,4,1,0,0,0,0,…} instead of {2,3,4,1,-,-,-,-,…}, then you should also apply a multiplicative masking by {1,1,1,1,0,0,0,0,…} on the result of the rotation by 1.

Thanks, that makes sense to me! I was just wondering if I was missing some operation that could make this easier to handle, but this confirms my understanding of how rotation works.

I’m trying to implement the diagonal matrix multiplication as described here, which involves rotating the vector to multiply with the diagonals.