Can we query an encrypted vector and output matching values?

Hey guys I’m still trying to figure out the possibilities i have with this library. I was wondering if I could also create some kind of “queries” to get values out of an encrypted vector, that match the condition.

Just think of a vector that acts like a database:

vector<double> v = {0.4567, 1.4567, 0.4634, 5.7870, 2.9087};
auto ct_v = Enc(v);

The query is: “Give me all values lower than 1 out of ct_v
The result i would wish for is (pseudocode):

auto ct_result = queryEncVector(ct_v, condition);
Plaintext ptResult;
cc->Decrypt(sk, ct_result, &ptResult);

So the result vector looks like this:

ptResult = {0.4567, 0.4634};

So I know there is not straightforward way for this but i wonder how that could work with the operations we have. Do you have an approach for this?

You need to implement a homomorphic comparison - less than in your case.

  1. Evaluate less than on your vector to get an encrypted indicator vector of ones and zeros - one where ‘less than’ is true, and zero otherwise.
  2. Multiply the encrypted indicator vector with your encrypted data point-wise and return the result.

Implementing homomorphic comparison is possible but quite involved. Check the literature on that considering the scheme(s) you work with.