Files
tfhe-rs/tfhe/docs/fhe-computation/operations/string-operations.md
2025-07-23 11:09:23 +02:00

6.2 KiB

String operations

This document details the string operations supported by TFHE-rs.

clear name fhe name first input type second input type third input type
eq eq FheAsciiString FheAsciiString or ClearString
ne ne FheAsciiString FheAsciiString or ClearString
le le FheAsciiString FheAsciiString or ClearString
ge ge FheAsciiString FheAsciiString or ClearString
lt lt FheAsciiString FheAsciiString or ClearString
gt gt FheAsciiString FheAsciiString or ClearString
len len FheAsciiString
is_empty is_empty FheAsciiString
eq_ignore_ascii_case eq_ignore_case FheAsciiString FheAsciiString or ClearString
to_lowercase to_lowercase FheAsciiString
to_uppercase to_uppercase FheAsciiString
contains contains FheAsciiString FheAsciiString or ClearString
ends_with ends_with FheAsciiString FheAsciiString or ClearString
starts_with starts_with FheAsciiString FheAsciiString or ClearString
find find FheAsciiString FheAsciiString or ClearString
rfind rfind FheAsciiString FheAsciiString or ClearString
strip_prefix strip_prefix FheAsciiString FheAsciiString or ClearString
strip_suffix strip_suffix FheAsciiString FheAsci---iString or ClearString
concat concat FheAsciiString FheAsciiString
repeat repeat FheAsciiString u16 or u32 or i32 or usize or (FheUint16, u16)
trim_end trim_end FheAsciiString
trim_start trim_start FheAsciiString
trim trim FheAsciiString
replace replace FheAsciiString FheAsciiString
replacen replacen FheAsciiString FheAsciiString or ClearString u16 or u32 or i32 or usize or (FheUint16, u16)

The following example shows how to perform string operations:

use tfhe::prelude::*;
use tfhe::{
    generate_keys, set_server_key, ConfigBuilder, FheAsciiString,
};
    
fn main() -> Result<(), Box<dyn std::error::Error>> {
    
    let config = ConfigBuilder::default().build();
    let (client_key, server_key) = generate_keys(config);
    set_server_key(server_key);
    
    let string1 = FheAsciiString::try_encrypt("tfhe-RS", &client_key).unwrap();
    let string2 = FheAsciiString::try_encrypt("TFHE-rs", &client_key).unwrap();
    let is_eq = string1.eq_ignore_case(&string2);

    assert!(is_eq.decrypt(&client_key));

    Ok(())
}