Ciphertext type for lookup table values

Hi Zama team,

I’m trying to implement the lookup operation as follows: given an encryption of a boolean value b (Enc(b)), and two plaintext elements v_0 and v_1 (integers), use Enc(b) select one of them and output encryption of v_b (Enc(v_b)). I saw in the TFHE-rs documentation that there is a cmux function—if I use cmux, would the output of cmux be the encryption of v_b? And would the output be an integer-type ciphertext so that I can directly do “add” or “mult” on the ciphertext?

Thanks for this amazing library and any information will be of great help!


Hello @Yulia_M

We do have a cmux function for boolean and one in the low level core_crypto API, but not at the shortint/integer level at the moment.

However you can easily write it yourself :slight_smile:

I’ll give you a shortint example you’ll be able to adapt it for integer.

use tfhe::shortint::*;

pub fn main() {
    let params = parameters::PARAM_MESSAGE_2_CARRY_2;

    let (cks, sks) = gen_keys(params);

    let msg_true = 3u64;
    let msg_false = 2u64;
    let control_bit = 1u64;

    let mut ct_true = cks.encrypt(msg_true);
    let mut ct_false = cks.encrypt(msg_false);
    let mut ct_control = cks.encrypt(control_bit);

    let mut res = sks.smart_sub(&mut ct_true, &mut ct_false);

    println!("msg_true - msg_false: {}", cks.decrypt_message_and_carry(&res));

    let mut res = sks.smart_mul_lsb(&mut res, &mut ct_control);

    println!("mul: {}", cks.decrypt_message_and_carry(&res));

    let res = sks.smart_add(&mut res, &mut ct_false);

    println!("cmux: {}", cks.decrypt_message_and_carry(&res));
1 Like