# I am encrypting a vector into ciphertext, and I want to exchange some values in the ciphertext for each other. What should I do?

**URL:** <https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711>\
**Category:** FHE Questions\
**Created:** [July 20, 2023, 8:31am UTC](https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711 "2023-07-20T08:31:35Z")\
**Posts on this page:** 4\
**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 20, 2023, 8:31am UTC](https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711/1 "2023-07-20T08:31:35Z")

</div>

I am encrypting a vector into ciphertext, and I want to exchange some values in the ciphertext for each other. What should I do?

---

<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 20, 2023, 1:02pm UTC](https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711/2 "2023-07-20T13:02:46Z")

</div>

What do you mean? Something like

```auto
v1 = [1,2,3, 0, 0, 0, 0]
v2 = [4,5,6, 0, 1, 10, 20]

v2.exchange(v1, [0, 1, 2])

```

which results in

```auto
v1 = [4, 5, 6, 0, 0, 0, 0]
v2 = [1, 2, 3, 0, 1, 10, 20]

```

? If so then it’s not possible with OpenFHE directly.

Edit: on further thought it should be possible by masking out values and storing them into temporary vectors, but that will incur more multiplications. You’re probably better off formulating it in a different way if possible

---

<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, 3:55pm UTC](https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711/3 "2023-07-20T15:55:03Z")

</div>

I want to rephrase the problem, that is, a vector is encrypted to the server, and then the index value corresponding to this ciphertext is also transmitted, I want to reorder this ciphertext according to this index or regenerate a vector with all 0 and then encrypt the ciphertext and then add the ciphertext with the corresponding value according to this index

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [July 24, 2023, 2:57pm UTC](https://openfhe.discourse.group/t/i-am-encrypting-a-vector-into-ciphertext-and-i-want-to-exchange-some-values-in-the-ciphertext-for-each-other-what-should-i-do/711/4 "2023-07-24T14:57:12Z")

</div>

I suggest reading [Slot-shuffling homomorphically - #4 by ypolyakov](https://openfhe.discourse.group/t/slot-shuffling-homomorphically/170/4)
