# How to compare Ciphertext？

such as Ciphertext1>Ciphertext2?
Ciphertext1=Ciphertext2?

Which FHE scheme are you using?

I use ckks
I want to sum a batch of ciphertext by rotation and compare the value sizes without decryption

I think you’d need scheme switching to go from CKKS<->DM/CGGI scheme to do that (Ahmad would know more). Anyways, Openfhe does not currently support that capability but I think it’s planning to. There are threads on this topic (search “scheme switching”)

1 Like

I may not have expressed my thoughts well, what I mean is that does openFHE support some function that can do the comparison of 2 encrypted numbers? Is there no such function?

The CKKS scheme does not. But the DM/CGGI does (I think) and so to leverage that, you’d need to do scheme switching to move from CKKS to DM/CGGI.

In general, you’re better off trying to find a way to phrase your computation in a way that does not require the comparison. This is because 1) we don’t support scheme switching just yet and 2) DM/CGGI is much much slower than CKKS

If you cannot avoid to perform comparison server-side, I suggest you to check this paper out .

The main idea basically is that you can rewrite

if (a > b) return foo();
else return boo();


as

comparison = sgn(a-b)
comparison_inv = 1 - comparison
return foo() * comparison + bar() * comparison_inv


and that paper helps you to write sgn(x) function (which is a little hard to approximate because of the jump, even by high degree chebyshev polynomials)

thank you .I will try it.

A good idea. I will try it,thanks!

Based on the paper comparison algorithm, can you please elaborate on how this can be used for range query?

You can use the \text{sgn}(x) to create a mask of [0, 1] and filter out only the results that you want

An alternative is to use EvalSign in the binfhe module (see Large-Precision Homomorphic Sign Evaluation using FHEW/TFHE Bootstrapping for technical details). Note that EvalCompare (based on EvalSign using TFHE/FHEW bootstrapping) will be added to CKKS in v1.1 (in roughly a month from now).

1 Like

I take the opportunity to ask, do you have a good reference for scheme switch?

I suggest waiting for the v1.1 release (ETA end of July) as we will include some documentation and examples there.

Before then, you can look at the prior scholarly papers (+ the already cited paper):

1 Like

Hi, is it now avaible the function EvalCompare in CKKS ?