# How to pack several vectors into a ciphertext

**URL:** <https://openfhe.discourse.group/t/how-to-pack-several-vectors-into-a-ciphertext/707>\
**Category:** FHE Questions\
**Created:** [July 19, 2023, 7:12am UTC](https://openfhe.discourse.group/t/how-to-pack-several-vectors-into-a-ciphertext/707 "2023-07-19T07:12:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenan](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@kenan](https://openfhe.discourse.group/u/kenan)\
**Post date:** [July 19, 2023, 7:12am UTC](https://openfhe.discourse.group/t/how-to-pack-several-vectors-into-a-ciphertext/707/1 "2023-07-19T07:12:05Z")

</div>

How to pack several vectors into a ciphertext？for example, I set batchsize=16, I want to encrypt three vectors of length 10 and package them into a ciphertext

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [July 19, 2023, 4:29pm UTC](https://openfhe.discourse.group/t/how-to-pack-several-vectors-into-a-ciphertext/707/2 "2023-07-19T16:29:03Z")

</div>

If your `batchsize` is 16 you can’t pack 3 ciphertexts of length 10 into it. At the least you’d need 30, no?

Also, one way to do something like this might be

```c++
VECTOR_SIZE = 10;
SMALLEST_POW_2_UP = 16;
NUM_VECTORS = 3;
std::vector<T> container_vec(SMALLEST_POW_2_UP * NUM_VECTORS);

vector_of_vectors = Vector[
    v1, // length 16, but the last (SMALLEST_POW_2_UP - VECTOR_SIZE) are just 0s
    v2, // length 16, but the last (SMALLEST_POW_2_UP - VECTOR_SIZE) are just 0s
    v3 // length 16, but the last (SMALLEST_POW_2_UP - VECTOR_SIZE) are just 0s
]

for (int i = 0; i < NUM_VECTORS; i++){
    curr_vec = vector_of_vectors[i] // one of the 3
    for (int j = 0; j < SMALLEST_POW_2_UP; j++){
        container_vec[(i * SMALLEST_POW_2_UP) + j] = curr_vec[j]
    }
}

```

The code isn’t valid C++ but hopefully gives you enough context for how to do what you’re asking. Bear in mind that you’ll have to keep a close eye on the indices and how you use the vectors

---

<div class="post-metadata">

**Author:** ![kenan](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@kenan](https://openfhe.discourse.group/u/kenan)\
**Post date:** [July 20, 2023, 1:10am UTC](https://openfhe.discourse.group/t/how-to-pack-several-vectors-into-a-ciphertext/707/3 "2023-07-20T01:10:47Z")

</div>

thanks,I understand it.
