@@ -386,6 +386,24 @@ pub trait BooleanFunctionImpl: Debug {
386
386
== ( ( 1 << self . variables_count ( ) ) - ( 1 << ( self . variables_count ( ) >> 1 ) ) ) >> 1
387
387
}
388
388
389
+ /// Returns `true` if the Boolean function is near-bent.
390
+ ///
391
+ /// A $n$-variable Boolean function is said to be *near-bent* if $n$ is odd,
392
+ /// and its [Walsh-Hamamard](#method.walsh_hadamard_values) spectrum contains all and only the 3 values $\\{0, \pm 2^{\frac{n+1}{2}}\\}$.
393
+ fn is_near_bent ( & self ) -> bool {
394
+ if self . variables_count ( ) & 1 == 0 {
395
+ return false ;
396
+ }
397
+ let absolute_walsh_allowed_value = 1 << ( ( self . variables_count ( ) + 1 ) >> 1 ) ;
398
+ let walsh_hadamard_spectrum = ( 0 ..=self . get_max_input_value ( ) )
399
+ . map ( |x| self . walsh_hadamard_transform ( x) )
400
+ . collect :: < HashSet < _ > > ( ) ;
401
+
402
+ walsh_hadamard_spectrum. len ( ) == 3 && walsh_hadamard_spectrum. iter ( ) . all ( |w| {
403
+ * w == 0 || * w == absolute_walsh_allowed_value || * w == -absolute_walsh_allowed_value
404
+ } )
405
+ }
406
+
389
407
/// Returns, if it exists, an annihilator function, its degree and the dimension of annihilator vector space.
390
408
///
391
409
/// The annihilator of a Boolean function $f$ is a non-null Boolean function $g$ such that:
@@ -642,7 +660,7 @@ pub trait BooleanFunctionImpl: Debug {
642
660
self . biguint_truth_table ( ) . to_u64 ( )
643
661
}
644
662
645
- // TODO almost (near?) bent , mul (and tt)
663
+ // TODO, mul (and tt)
646
664
}
647
665
648
666
/// This type is used to store a boolean function with any number of variables.
@@ -1325,6 +1343,22 @@ mod tests {
1325
1343
assert ! ( !boolean_function. is_bent( ) ) ;
1326
1344
}
1327
1345
1346
+ #[ test]
1347
+ fn test_is_near_bent ( ) {
1348
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "f9" )
1349
+ . unwrap ( ) ;
1350
+ assert ! ( boolean_function. is_near_bent( ) ) ;
1351
+
1352
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "ff" )
1353
+ . unwrap ( ) ;
1354
+ assert ! ( !boolean_function. is_near_bent( ) ) ;
1355
+
1356
+ // even variable count -> cannot be near-bent
1357
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "f9f9" )
1358
+ . unwrap ( ) ;
1359
+ assert ! ( !boolean_function. is_near_bent( ) ) ;
1360
+ }
1361
+
1328
1362
#[ test]
1329
1363
fn test_annihilator ( ) {
1330
1364
let boolean_function =
0 commit comments