boolcrypt.findpolyoptimal module

Find an affine equivalent permutation minimizing some objective function.

boolcrypt.findpolyoptimal.find_optimal_equiv_poly(lut, field=None, mode='random', minimize='deg', filename=None, verbose=False)[source]

Find an affine equivalent permutation minimizing some objective function.

Given F, finds G = B circ F circ A such that the polynomial representing G minimizes some objective function Obj.

B is taken linear (adding a constant would not minimize the objective function) and A is taken affine.

mode=”deg” minimizes the polynomial degree, mode=”terms” minimizes the number of term mode=”linear_terms” minimizes the number of linear terms x^(q^i)

mode=”random” tries random A and L mode=”all_matrices” iterates all invertible matrices (and constants) mode=”all_linearized” iterates all linearized polynomial (and constants).

>>> lut = get_lut_inversion(3)
>>> bin_matrix = sage.all.matrix(GF(2), 3, 3, [[1, 0, 0], [0, 1, 0], [1, 0, 1]]).inverse()
>>> new_lut = compose_matrix_lut(bin_matrix, lut)
>>> find_optimal_equiv_poly(new_lut, mode="all_matrices", minimize="terms", verbose=False)
6*x^5
boolcrypt.findpolyoptimal.find_optimal_equiv_anf(sbox_lut, mode='random', minimize='terms', filename=None, verbose=True)[source]

Find an affine equivalent permutation minimizing some objective function.

Given F, finds G = B circ F circ A such that the ANF representing G minimizes some objective function Obj.

B is taken linear (adding a constant would not minimize the objective function) and A is taken affine.

mode=”terms” minimizes the number of terms

mode=”random” tries random A and L mode=”all_matrices” iterates all invertible matrices (and constants) mode=”all_linearized” iterates all linearized polynomial (and constants).

>>> lut = [i for i in range(2**3)]
>>> bin_matrix = sage.all.matrix(GF(2), 3, 3, [[1, 0, 0], [0, 1, 0], [1, 0, 1]]).inverse()
>>> new_lut = compose_matrix_lut(bin_matrix, lut)
>>> list(find_optimal_equiv_anf(new_lut, mode="all_matrices", minimize="terms", verbose=False))
[x0, x1, x2]