Comparing ciphertexts and scalars

Dear Zama,

I just wanted to ask how would someone compare a ciphertext and a scalar in your library? If for example an integer was encrypted using the client key and at the server we want to compare the encrypted integer to a non-encrypted one knowing that we don’t have access to the client key and the server key cannot be used for encryption

Thank you in advance.

Sincerely,
Ali

There are different ways to compare, depending on what your ciphertext is, i.e. is it a RadixCiphertext of Ciphertext.

If you want to compare a RadixCiphertext(where secret key is used to encrypt an integer) you can use

let res = sk.smart_scalar_eq_parallelized(&mut cipher, scalar)

where sk is Radix Server Key

If you want to compare a Ciphertext (where secret key is used to encrypt a shortint) you can use

let equal = |x:u64|
    if x == scalar {
        1
    }else {
        0
    }
;
let acc = shortint_sk.generate_accumulator(&equal);
let res = shortint_sk.apply_lookup_table(&cipher, &acc);

where shortint_sk is Shortint Server Key

1 Like

hello @Professor_Ali @divyesh answer is good however for shortint you also have scalar comparison operations like ServerKey in tfhe::shortint::server_key - Rust

Also you can use so called “default operations” which are less error prone to use with respect to performance ServerKey in tfhe::shortint::server_key - Rust

Cheers

1 Like