# Encrypted vector processing in CKKS scheme

**URL:** <https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068>\
**Category:** Library Questions\
**Created:** [February 7, 2024, 11:41am UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068 "2024-02-07T11:41:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reaneling](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@Reaneling](https://openfhe.discourse.group/u/Reaneling)\
**Post date:** [February 7, 2024, 11:41am UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/1 "2024-02-07T11:41:41Z")

</div>

Hello, a question about the encrypted vector of the CKKS scheme.  
From the theory I understood that in principle it is possible to process members of encrypted vector separately.  
For example, I need to split the encrypted vector into two parts. In examples and documentation I did not find information on how to do it.  
Could you please tell me where I can find information on how to split an encrypted vector into two vectors, if it is possible at all.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [February 7, 2024, 12:45pm UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/2 "2024-02-07T12:45:34Z")

</div>

If I got you question, you can “split” an encrypted vector by masking as follows:

```auto
v = [1, 2, 3, 4]
v_1 = [1, 2, 3, 4] * [1, 1, 0, 0] = [1, 2, 0, 0]
v_1 = [1, 2, 3, 4] * [0, 0, 1, 1] = [0, 0, 3, 4]

```

---

<div class="post-metadata">

**Author:** ![Reaneling](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@Reaneling](https://openfhe.discourse.group/u/Reaneling)\
**Post date:** [February 7, 2024, 2:46pm UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/3 "2024-02-07T14:46:03Z")

</div>

Didn’t even think to use the method there, thanks!

---

<div class="post-metadata">

**Author:** ![Reaneling](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@Reaneling](https://openfhe.discourse.group/u/Reaneling)\
**Post date:** [February 7, 2024, 3:06pm UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/4 "2024-02-07T15:06:23Z")

</div>

But still wondering if I can process each element separately. For example

```auto
v = [1, 2, 3, 4, 5, 6]
v_1 = [1, 3, 5]
v_2 = [2, 4, 6]

```

This is necessary to add up the vectors. The way you’re doing it, it goes like this:

```auto
v = [1, 2, 3, 4, 5, 6]
v_1 = [1, 0, 3, 0, 5, 0]
v_2 = [0, 2, 0, 4, 0, 6]
v_3 = [1, 0, 3, 0, 5, 0] + [0, 2, 0, 4, 0, 6] = [1, 2, 3, 4, 5, 6]

```

Maybe I can do that with a rotation? But from the example I didn’t quite understand how it works.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [February 7, 2024, 4:42pm UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/5 "2024-02-07T16:42:16Z")

</div>

Uhm, I don’t understand your goal. If you want to add pair of values you can do it with a rotation:

```auto
v = [1, 2, 3, 4]
v_r = rot(v, 1) #[2, 3, 4, 1]

v_res = v + v_r = [1, 2, 3, 4] + [2, 3, 4, 1]

```

But perhaps I am missing your point.

---

<div class="post-metadata">

**Author:** ![dcousins](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/dcousins/32/71_2.png) [@dcousins](https://openfhe.discourse.group/u/dcousins)\
**Post date:** [February 12, 2024, 3:17pm UTC](https://openfhe.discourse.group/t/encrypted-vector-processing-in-ckks-scheme/1068/6 "2024-02-12T15:17:51Z")

</div>

you cannot process an individual element in an encrypted vector. you must process all elements with the same instruction (that is why it is called SIMD – single instruction multiple data.  
one thing about rotation, you are rotating the ENTIRE vector which for CKKS is ringsize/2 . if you do not fully load the vector, then you will get zeros (+small noise) rotating in from the end.  
see [openfhe-development/src/pke/examples/rotation.cpp at main · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/rotation.cpp)  
for examples.

for example when we do a dot product of two vectors, we to the hadamard multiplication of the two then we take the result, and add it to a copy rotated by 1, repeat rotated by 2, 4, 8 etc. until we basically have a vector of all the same values, which is the summation. (note there is an input variable that lets you specify the sublength (power of 2) of the vector you actually care about (assuming the remaining elements are zero) – that limits where we stop.
