# Data analysis in ciphertext state

**URL:** <https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990>\
**Category:** FHE Use Cases\
**Tags:** questions\
**Created:** [December 22, 2023, 2:53am UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990 "2023-12-22T02:53:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazyRobert](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@crazyRobert](https://openfhe.discourse.group/u/crazyRobert)\
**Post date:** [December 22, 2023, 2:53am UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/1 "2023-12-22T02:53:31Z")

</div>

Hello,  
is there a method in CKKS ciphertext that can access the i-th number in a vector, such as two vectors? I just want to know which vector has a larger number in the i-th position. How can this be implemented

---

<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:** [December 22, 2023, 10:13pm UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/2 "2023-12-22T22:13:16Z")

</div>

Accessing an i-th number is quite simple (it can be done using a rotation). Comparing two numbers (in a general way) is harder (computationally expensive in FHE). It can either be done using FHEW/TFHE or by switching from CKKS to FHEW.TFHE (`EvalSign` procedure in OpenFHE) or using a polynomial approximation of the sign function (for the latter, there is a challenge at [https://fherma.io/challenges](https://fherma.io/challenges)). There are special-purpose algorithms that are much faster but they are not typically compatible with other homomorphic operations over integers/real numbers.

---

<div class="post-metadata">

**Author:** ![crazyRobert](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@crazyRobert](https://openfhe.discourse.group/u/crazyRobert)\
**Post date:** [December 23, 2023, 11:13am UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/3 "2023-12-23T11:13:15Z")

</div>

Thank you for your answer. I have looked at the example code and it seems that the result greater than or less than 0 still needs to be decrypted to be visible?

---

<div class="post-metadata">

**Author:** ![crazyRobert](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@crazyRobert](https://openfhe.discourse.group/u/crazyRobert)\
**Post date:** [December 25, 2023, 2:20am UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/4 "2023-12-25T02:20:35Z")

</div>

Actually, I want to calculate min/max under ciphertext. My idea is to first find x=sign (A-B), and then calculate max=x·A+(1-x)·B, but in FHEW.TFHE, the EvalSign function returns the value which seems to be of Boolean type and cannot be directly multiplied?

---

<div class="post-metadata">

**Author:** ![crazyRobert](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@crazyRobert](https://openfhe.discourse.group/u/crazyRobert)\
**Post date:** [December 25, 2023, 8:46am UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/5 "2023-12-25T08:46:03Z")

</div>

I looked at your example of comparison of ciphertext, but I found a contradiction, which is that after comparing the ciphertext, I must decrypt it to obtain which ciphertext is larger or smaller. If I consider a scenario where the client uploads ciphertext and the server analyzes it, the server needs to decrypt it to complete the comparison. So he can decrypt the comparison results, which means he can also directly decrypt the ciphertext. What is the significance of doing so? How should I implement this system?

---

<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:** [December 27, 2023, 9:34pm UTC](https://openfhe.discourse.group/t/data-analysis-in-ciphertext-state/990/6 "2023-12-27T21:34:34Z")

</div>

For min/argmin, I suggest looking at the following example: [openfhe-development/src/pke/examples/scheme-switching.cpp at v1.1.2 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/v1.1.2/src/pke/examples/scheme-switching.cpp#L875)

The result of comparison does not need to be decrypted. The FHE computations can be continued after this.
