@@ -33,26 +33,33 @@ use num_traits::Num;
33
33
fn main () {
34
34
// Create a Boolean function from its string truth table
35
35
const TRUTH_TABLE_STR : & 'static str = " 0113077C165E76A8" ;
36
- let f : BooleanFunction = BooleanFunction :: from_hex_string_truth_table (TRUTH_TABLE_STR ). unwrap ();
36
+ let f : BooleanFunction = BooleanFunction :: from_hex_string_truth_table (TRUTH_TABLE_STR )
37
+ . unwrap ();
37
38
38
39
// How many variables does the function have?
39
40
assert_eq! (f . variables_count (), 6 );
40
41
41
42
// Check if the function is bent
42
43
assert! (f . is_bent ());
43
44
44
- // If you already know that the function has a small number of variables, you can use SmallBooleanFunction
45
+ // If you already know that the function has a small number of variables,
46
+ // you can use SmallBooleanFunction
45
47
// It will be faster runtime and use less memory
46
- let f_small : SmallBooleanFunction = SmallBooleanFunction :: from_truth_table (0xac90 , 4 ). unwrap ();
48
+ let f_small : SmallBooleanFunction = SmallBooleanFunction :: from_truth_table (0xac90 , 4 )
49
+ . unwrap ();
47
50
assert! (f_small . is_bent ());
48
51
assert! (! f_small . is_balanced ()); // A bent function is not balanced
49
52
// ANF of the function, `*` is AND and `+` is XOR
50
- assert_eq! (f_small . algebraic_normal_form (). to_string (), " x0*x2 + x1*x2 + x1*x3 + x2*x3 + x2" );
53
+ assert_eq! (
54
+ f_small . algebraic_normal_form (). to_string (),
55
+ " x0*x2 + x1*x2 + x1*x3 + x2*x3 + x2" );
51
56
52
57
// If your function has more than 6 variables, you can use BigBooleanFunction
53
58
// So that you will avoid runtime calls to the V-table
54
59
const AES_COMP_TT : & 'static str = " 4f1ead396f247a0410bdb210c006eab568ab4bfa8acb7a13b14ede67096c6eed" ;
55
- let f_big : BigBooleanFunction = BigBooleanFunction :: from_truth_table (BigUint :: from_str_radix (AES_COMP_TT , 16 ). unwrap (), 8 );
60
+ let f_big : BigBooleanFunction = BigBooleanFunction :: from_truth_table (
61
+ BigUint :: from_str_radix (AES_COMP_TT , 16 ). unwrap (),
62
+ 8 );
56
63
assert_eq! (f_big . nonlinearity (), 112 ); // AES S-Box has a nonlinearity of 112
57
64
}
58
65
```
@@ -89,7 +96,8 @@ fn main() {
89
96
// Parallel exhaustive search on all 4-variable Boolean functions
90
97
let count = (0 .. (1 << 16 )). into_par_iter ()
91
98
. filter (| truth_table | {
92
- let f : BooleanFunction = BooleanFunction :: from_u64_truth_table (* truth_table , 4 ). unwrap ();
99
+ let f : BooleanFunction = BooleanFunction :: from_u64_truth_table (* truth_table , 4 )
100
+ . unwrap ();
93
101
f . is_balanced ()
94
102
}). count ();
95
103
assert_eq! (count , 12870 );
0 commit comments