Magma code

General Functions

The following functions are used for computing common properties of vectorial Boolean functions such as the values of the Walsh transform, the differential uniformity, the derivatives, etc. All these functions are available as a single file.

  • Walsh coefficients of a vectorial Boolean function
    function Walsh2d(F,a,b)
     //compute the expressions inside the trace in the exponent
     intrace := [ b*Evaluate(F,x) + a*x : x in BaseRing(F) ];
     //compute the traces, i.e. the exponents of (-1)
     traces := [ AbsoluteTrace(BaseRing(F) ! x) : x in intrace ];
     //the traces should all be zeros and ones; howver, we still
     //manually conver them to real zeros and ones so that no coercion
     //problems arise
     traces := [ (x eq 0) select (RealField() ! 0) else (RealField() ! 1) : x in traces];
     //raise (-1) to the appropriate powers and sum the results
     powers := [ (-1)^( RealField() ! x ) : x in traces ];
     return &+powers;
    end function;
  • APN Test
    function isAPN(F)
    	/* Check whether the image of every single derivative is of size 2^(n-1); this
    	 * should allow non-APN functions to be eliminated more quickly. */
    	n := getDimension(F);
    
    	for a in BaseRing(F) do
    		if a eq 0 then
    			continue;
    		end if;
    
    		derivative_image := { Evaluate(F,x) + Evaluate(F,x+a) : x in BaseRing(F) };
    		if #derivative_image ne 2^(n-1) then
    			return false;
    		end if;
    	end for;
    
    	return true;
    end function;
  • CCZ-Equivalence
    function isAPNo(poly_f, p, n)
        FF := FiniteField(p,n);
        f:= func;
        for i in [0 .. p^n-2] do
            a := z^i;
            imageSet := {* *};
            for x in FF do
                b := f(x+a)-f(x);
                Include(~imageSet, b);
            end for;
            print imageSet;
            aDU, pos := Maximum(Multiplicities(imageSet));
            if aDU gt 2 then
                return false;
            end if;
        end for;
        return true;
    end function;
    
    function genLinearCodeFromFunction(poly_f, p, n)
        GF := FiniteField(p,n);
        f:= func;
        M := Matrix(FiniteField(p), 2*n+1, p^n,
                        [1: x in GF]
                    cat [Trace(z^i * x): x in GF, i in [0..n-1]]
                    cat [Trace(z^i * f(x)): x in GF, i in [0..n-1]]
                    );
        // printf "GenMatrix :=%o\n", M;
        return LinearCode(M);
    end function;
    
    function isCCZEquivalent(f1, f2, p, n)
        Code1 := genLinearCodeFromFunction(f1, p, n);
        Code2 := genLinearCodeFromFunction(f2, p, n);
        res, map := IsIsomorphic(Code1, Code2);
        return res;
    end function;
  • Plateauedness test
    function isPlateaued(F)
        for b in BaseRing(F) do
            if b eq 0 then continue; end if;
            W := { Walsh2d(F,a,b) : a in BaseRing(F) };
            if #W gt 3 then
                            return false;
                    end if;
            amplitude := 0;
            for w in W do
                if w ne 0 then
                    if amplitude eq 0 then
                        amplitude := AbsoluteValue(w);
                    else
                        if AbsoluteValue(w) ne amplitude then
                                                    return false;
                                            end if;
                    end if;
                end if;
            end for;
        end for;
        return true;
    end function;
    
  • Switching class representatives
        /* Lists of representatives from all switching classes for dimensions 6 through 8. */
        function listAPN6()
        u := PrimitiveElement(GF(2^6));
        x := PolynomialRing(GF(2^6)).1;
        G6:=[
        x^3,
        x^3 + u^11*x^6 + u*x^9,
        u*x^5 + x^9 + u^4*x^17 + u*x^18 + u^4*x^20 + u*x^24 + u^4*x^34 + u*x^40,
        u^7*x^3 + x^5 + u^3*x^9 + u^4*x^10 + x^17 + u^6*x^18,
        x^3 + u*x^24 + x^10,
        x^3 + u^17*(x^17 + x^18 + x^20 + x^24),
        x^3 + u^11*x^5 + u^13*x^9 + x^17 + u^11*x^33 + x^48,
        u^25*x^5 + x^9 + u^38*x^12 + u^25*x^18 + u^25*x^36,
        u^40*x^5 + u^10*x^6 + u^62*x^20 + u^35*x^33 + u^15*x^34 + u^29*x^48,
        u^34*x^6 + u^52*x^9 + u^48*x^12 + u^6*x^20 + u^9*x^33 + u^23*x^34 + u^25*x^40,
        x^9 + u^4*(x^10 + x^18) + u^9*(x^12 + x^20 + x^40),
        u^52*x^3 + u^47*x^5 + u*x^6 + u^9*x^9 + u^44*x^12 + u^47*x^33 + u^10*x^34 + u^33*x^40,
        u*(x^6 + x^10 + x^24 + x^33) + x^9 + u^4*x^17,
        x^3 + u^17*(x^17 + x^18 + x^20 + x^24) + u^14*((u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)+ (u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)^2 + (u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)^4+ (u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)^8+ (u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)^16+ (u^52*x^3 + u^6*x^5 + u^19*x^7 + u^28*x^11 + u^2*x^13)^32+ (u^2*x)^9 +(u^2*x)^18 +(u^2*x)^36 + x^21+x^42)
        ];
        return G6;
    end function;
    
    
    function listAPN7()
    u := PrimitiveElement(GF(2^7));
        x := PolynomialRing(GF(2^7)).1;
        G7:=[
        x^3,
        x^3 + variableTrace(x^9),
        x^34 + x^18 + x^5,
        x^3 + x^17 + x^33 + x^34,
        x^5,
        x^9,
        x^13,
        x^57,
        x^(2^7-1-1),
        x^65 + x^10 + x^3,
        x^3 + x^9 + x^18 + x^66,
        x^3 + x^12 + x^17 + x^33,
        x^3 + x^17 + x^20 + x^34 + x^66,
        x^3 + x^20 + x^34 + x^66,
        x^3 + x^12 + x^40 + x^72,
        x^3 + x^5 + x^10 + x^33 + x^34,
        x^3 + x^6 + x^34 + x^40 + x^72,
        x^3 + x^5 + x^6 + x^12 + x^33 + x^34,
        u^2*x^96 + u^78*x^80 + u^121*x^72 + u^49*x^68 + u^77*x^66 + u^29*x^65 + u^119*x^48 + u^117*x^40 + u^28*x^36 +
        u^107*x^34 +u^62*x^33 +u^125*x^24 +u^76*x^20 +u^84*x^18 +u^110*x^17 +u^49*x^12 +u^102*x^10 +u^69*x^9 +
        u^14*x^6 + x^5 + x^3];
        return G7;
    end function;
    
    function listAPN8()
        w := PrimitiveElement(GF(2^8));
        x := PolynomialRing(GF(2^8)).1;
        G8:=[x^3, x^9, x^3+variableTrace(x^9),  x^9+variableTrace(x^3),
    
        x^3+w^245*x^33+w^183*x^66+w^21*x^144,
    
        x^3 + w^65*x^18+w^120*x^66+w^135*x^144,
    
        w^188*x^192+w^129*x^144+w^172*x^132+ w^138*x^129+w^74*x^96+w^244*x^72+w^22*x^66+ w^178*x^48+w^150*x^36+w^146*x^33+w^6*x^24+ w^60*x^18+w^80*x^12+w^140*x^9+w^221*x^6+w^19*x^3,
    
        w^37*x^192+w^110*x^144+w^40*x^132+w^53*x^129
        +w^239*x^96+w^235*x^72+w^126*x^66+w^215*x^48+
        w^96*x^36+w^29*x^33+w^19*x^24+w^14*x^18+
        w^139*x^12+w^230*x^9+w^234*x^6+w^228*x^3,
    
        w^242*x^192+w^100*x^144+w^66*x^132+w^230*x^129+
        w^202*x^96+w^156*x^72+w^254*x^66+w^18*x^48+
        w^44*x^36+w^95*x^33+w^100*x^24+w^245*x^18+
        w^174*x^12+w^175*x^9+w^247*x^6+w^166*x^3,
    
        w^100*x^192+ w^83*x^144+ w^153*x^132+ w^65*x^129+ w^174*x^96+ w^136*x^72+
        w^46*x^66+ w^55*x^48+ w^224*x^36+ w^180*x^33+ w^179*x^24+w^226*x^18+ w^54*x^12+ w^168*x^9+ w^89*x^6+ w^56*x^3,
    
        w^77*x^192+ w^133*x^144+ w^47*x^132+ w^229*x^129+ w^23*x^96+ w^242*x^72+
        w^242*x^66+ w^245*x^48+ w^212*x^36+
        w^231*x^33+ w^174*x^24+ w^216*x^18+
        w^96*x^12+ w^253*x^9+ w^154*x^6+ w^71*x^3,
    
        w^220*x^192+ w^94*x^144+ w^70*x^132+ w^159*x^129+ w^145*x^96+w^160*x^72+ w^74*x^66+ w^184*x^48+ w^119*x^36+ w^106*x^33+w^253*x^24+ w*x^18+ w^90*x^12+ w^169*x^9+ w^118*x^6+
        w^187*x^3,
    
        w^98*x^192+ w^225*x^144+ w^111*x^132+ w^238*x^129+ w^182*x^96+ w^125*x^72+
        w^196*x^66+ w^219*x^48+ w^189*x^36+
        w^199*x^33+ w^181*x^24+ w^110*x^18+
        w^19*x^12+ w^175*x^9+ w^133*x^6+ w^47*x^3,
    
        w^236*x^192+ w^212*x^160+ w^153*x^144+ w^185*x^136+ w^3*x^132+w^89*x^130+ w^189*x^129+ w^182*x^96+ w^105*x^80+ w^232*x^72+w^219*x^68+ w^145*x^66+ w^171*x^65+ w^107*x^48+ w^179*x^40+
        w^227*x^36+ w^236*x^34+ w^189*x^33+ w^162*x^24+ w^216*x^20+w^162*x^18+ w^117*x^17+ w^56*x^12+ w^107*x^10+ w^236*x^9+w^253*x^6+ w^180*x^5+ w^18*x^3,
    
        w^27*x^192+ w^167*x^144+ w^26*x^132+w^231*x^129+ w^139*x^96+w^30*x^72+ w^139*x^66+ w^203*x^48+ w^36*x^36+ w^210*x^33+w^195*x^24+ w^12*x^18+ w^43*x^12+ w^97*x^9+ w^61*x^6+w^39*x^3,
    
        w^6*x^192+ w^85*x^144+ w^251*x^132+ w^215*x^129+ w^229*x^96+ w^195*x^72+ w^152*x^66+ w^173*x^48+ w^209*x^36+ w^165*x^33+ w^213*x^24+ w^214*x^18+ w^158*x^12+ w^146*x^9+ x^6+ w^50*x^3,
    
        w^164*x^192+ w^224*x^144+ w^59*x^132+ w^124*x^129+ w^207*x^96+ w^211*x^72+ w^5*x^66+ w^26*x^48+ w^20*x^36+ w^101*x^33+ w^175*x^24+ w^241*x^18+ x^12+ w^15*x^9+ w^217*x^6+ w^212*x^3,
    
        x^3+ x^17+w^16*(x^18+x^33)+w^15*x^48,
    
        x^3+ w^24*x^6+w^182*x^132+w^67*x^192,
    
        x^3+x^6+x^68+x^80+x^132+x^160,
    
        x^3+x^5+x^18+x^40+x^66,
    
        x^3+x^12+x^40+x^66+x^130,
    
        x^57];
        
        return G8;
    end function;