use crate::ai::{AlgebraicImmunity, RestrictedAlgebraicImmunity};
pub struct BooleanFunction {
t_table: Vec<u8>,
n: usize,
}
impl BooleanFunction {
pub fn new(truth_table: Vec<u8>) -> Self {
let len = truth_table.len();
assert!(
len.is_power_of_two(),
"Truth table length must be a power of two."
);
let n: usize = (usize::BITS - 1 - len.leading_zeros()) as usize;
BooleanFunction {
t_table: truth_table,
n: n,
}
}
pub fn from_truth_table(truth_table: Vec<u8>) -> Self {
Self::new(truth_table)
}
pub fn truth_table(&self) -> Vec<u8> {
self.t_table.clone()
}
pub fn algebraic_immunity(&self) -> usize {
AlgebraicImmunity::algebraic_immunity(self.t_table.clone(), self.n)
}
pub fn restricted_algebraic_immunity(&self, subset: Vec<usize>) -> usize {
RestrictedAlgebraicImmunity::algebraic_immunity(self.t_table.clone(), subset, self.n)
}
}