-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparison sequence of enc_numbers #520
Comments
Is this what you're looking for? import numpy as np
from concrete import fhe
configuration = fhe.Configuration(
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location=".keys",
single_precision=False,
)
@fhe.compiler({"numbers": "encrypted", "query": "encrypted"})
def filtering(numbers, query):
is_greater = numbers > query
shifted_numbers = numbers * 2 # open space for a single bit at the end
combined_numbers_and_is_greater = shifted_numbers + is_greater # put is_greater to that bit
def extract(combination):
is_greater = (combination % 2) == 1 # extract is_greater back from packing
if_true = combination // 2 # if is greater is true, we unpack the number and use it
if_false = 0 # otherwise we set the element to zero
return np.where(is_greater, if_true, if_false) # and apply the operation
return fhe.univariate(extract)(combined_numbers_and_is_greater)
inputset = [
(
np.random.randint(0, 10, size=(5,)),
np.random.randint(0, 10, size=()),
)
for _ in range(100)
]
circuit = filtering.compile(inputset, configuration, verbose=True)
print(filtering(np.array([1, 3, 2, 5, 4]), 3))
print(circuit.encrypt_run_decrypt([1, 3, 2, 5, 4], 3)) prints
Few notes:
Let us know if this helps! |
FYI this workaround is part of the new tutorial page in the documentation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have some questions, say I have a set or sequence of encrypted numbers outsourced to the cloud. Now client sent an encrypted range query to the server. Now I want the server to do the computation and return the value whose range is greater or equal to (>=) given numbers (ignore the lower numbers, filtered). How can this be implemented using concrete, any library, or pseudocode that explains this setup? Any help
The text was updated successfully, but these errors were encountered: