| Download
Project: Bent-functions
Path: Boolean-Cayley-graphs/sage-code / bent_function_extended_affine_representative_polynomials.sage
Views: 8800r"""1Boolean polynomial representatives of extended affine equivalence classes2of bent functions.3"""45#*****************************************************************************6# Copyright (C) 2016 Paul Leopardi [email protected]7#8# Distributed under the terms of the GNU General Public License (GPL)9# as published by the Free Software Foundation; either version 2 of10# the License, or (at your option) any later version.11# http://www.gnu.org/licenses/12#*****************************************************************************1314from sage.crypto.boolean_function import BooleanFunction151617def bent_function_extended_affine_representative_polynomials_dimension_2():18r"""19The Boolean polynomial p2[1] is the representative of the single20extended affine equivalence class of bent functions in two variables,21as mentioned at 7.1 of Tokareva 2015.22"""23R2.<x1,x2> = BooleanPolynomialRing(2)24p2 = [None]*225p2[1] = x1*x226return p2272829def bent_function_extended_affine_representative_polynomials_dimension_4():30r"""31The Boolean polynomial p4[1] is the representative of the single32extended affine equivalence class of bent functions in four variables,33as mentioned at 7.1 of Tokareva 2015.34"""35R4.<x1,x2,x3,x4> = BooleanPolynomialRing(4)36p4 = [None]*237p4[1] = x1*x2 + x3*x438return p4394041def bent_function_extended_affine_representative_polynomials_dimension_6():42r"""43The Boolean polynomials p6[i] for from 1 to 4 are the representatives of44the extended affine equivalence classes of bent functions in six variables,45as listed at 7.2 of Tokareva 2015, with citation [318] to Rothaus 1976.46"""47R6.<x1,x2,x3,x4,x5,x6> = BooleanPolynomialRing(6)48p6 = [None]*549p6[1] = x1*x2 + x3*x4 + x5*x650p6[2] = x1*x2*x3 + x1*x4 + x2*x5 + x3*x651p6[3] = x1*x2*x3 + x2*x4*x5 + x1*x2 + x1*x4 + x2*x6 + x3*x5 + x4*x552p6[4] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x1*x4 + x2*x6 + x3*x4 + x3*x5 + x3*x6 + x4*x5 + x4*x653return p6545556def bent_function_extended_affine_representative_polynomials_dimension_8():57r"""58The Boolean polynomials p8[i] for from 1 to 10 are the representatives of59the extended affine equivalence classes of bent functions in 8 variables,60with degree up to 3, as listed at 7.3 of Tokareva 2015,61with citation [167] to Hou 1998.62"""63R8.<x1,x2,x3,x4,x5,x6,x7,x8> = BooleanPolynomialRing(8)64p8 = [None]*1165p8[1] = x1*x2 + x3*x4 + x5*x6 + x7*x866p8[2] = x1*x2*x3 + x1*x4 + x2*x5 + x3*x6 + x7*x867p8[3] = x1*x2*x3 + x2*x4*x5 + x3*x4 + x2*x6 + x1*x7 + x5*x868p8[4] = x1*x2*x3 + x2*x4*x5 + x1*x3 + x1*x5 + x2*x6 + x3*x4 + x7*x869p8[5] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x3*x5 + x2*x6 + x2*x5 + x1*x7 + x4*x870p8[6] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x3*x5 + x1*x3 + x1*x4 + x2*x7 + x6*x871p8[7] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x3*x5 + x2*x6 + x2*x5 + x1*x2 + x1*x3 + x1*x4 + x7*x872p8[8] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x3*x5 + x1*x6 + x2*x7 + x4*x873p8[9] = x1*x2*x7 + x3*x4*x7 + x5*x6*x7 + x1*x4 + x3*x6 + x2*x5 + x4*x5 + x7*x874p8[10] = x1*x2*x3 + x2*x4*x5 + x3*x4*x6 + x1*x4*x7 + x3*x5 + x2*x7 + x1*x5 + x1*x6 + x4*x875return p8767778def bent_function_extended_affine_representative_polynomials(dimension):79r"""80Return the list of Boolean polynomial representatives of81extended affine equivalence classes of bent functions,82in the given dimension.83"""84dispatcher = {852: bent_function_extended_affine_representative_polynomials_dimension_2,864: bent_function_extended_affine_representative_polynomials_dimension_4,876: bent_function_extended_affine_representative_polynomials_dimension_6,888: bent_function_extended_affine_representative_polynomials_dimension_889}90return dispatcher[dimension]()919293def print_latex_table_of_representative_polynomials(94dimension, start=1, width=140):95r"""96For given dimension, print, in LaTeX format, the table97of algebraic normal forms of bent functions given by98the representative polynomials for that dimension.99100Example:101102sage: print_latex_table_of_representative_polynomials(4)103\def\arraystretch{1.2}104\begin{array}{|cl|}105\hline106\text{Class} &107\text{Representative}108\\109\hline110\,[f_{ 4 , 1 }] & f_{ 4 , 1 } :=111\begin{array}{l}112x_{0} x_{1} + x_{2} x_{3}113\end{array}114\\115\hline116\end{array}117118"""119print("\\def\\arraystretch{1.2}")120print("\\begin{array}{|cl|}")121print("\\hline")122print("\\text{Class} &")123print("\\text{Representative}")124print("\\\\")125print("\\hline")126127p = bent_function_extended_affine_representative_polynomials(dimension)128129for n in range(start, len(p)):130boolf = BooleanFunction(p[n])131f = boolf.algebraic_normal_form()132print("\\,[f_{",dimension,",",n,"}] & f_{",dimension,",",n,"} :=")133print("\\begin{array}{l}")134lf = latex(f)135cut = 0136while cut >= 0 and len(lf) > width:137cut = lf.rfind('+', 0, width)138if cut > 0:139print(lf[:cut])140if cut >= 0 and cut < len(lf):141print("\\\\")142print("+\\,", end=' ')143lf = lf[cut + 1:]144print(lf)145print("\\end{array}")146print("\\\\")147print("\\hline")148print("\\end{array}")149150151