algebraic immunity
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from sage.all import BooleanPolynomialRing
|
from sage.all import BooleanPolynomialRing
|
||||||
from sage.crypto.sbox import SBox
|
from sage.crypto.sbox import SBox
|
||||||
|
from sage.crypto.boolean_function import BooleanFunction
|
||||||
|
|
||||||
from tea3.tea3model import F31, F32
|
from tea3.tea3model import F31, F32
|
||||||
|
|
||||||
@@ -45,7 +46,44 @@ def _truth_table(vecfun):
|
|||||||
def _sbox(vecfun):
|
def _sbox(vecfun):
|
||||||
return SBox(_truth_table(vecfun), big_endian=False)
|
return SBox(_truth_table(vecfun), big_endian=False)
|
||||||
|
|
||||||
|
def _coordinate_boolean_functions(vecfun):
|
||||||
|
tt = _truth_table(vecfun)
|
||||||
|
|
||||||
|
coords = [[] for _ in range(8)]
|
||||||
|
|
||||||
|
for value in tt:
|
||||||
|
for i in range(8):
|
||||||
|
coords[i].append((value >> i) & 1)
|
||||||
|
|
||||||
|
return [BooleanFunction(coord) for coord in coords]
|
||||||
|
|
||||||
|
|
||||||
|
def study_algebraic_immunity(vecfun, name="F"):
|
||||||
|
bfs = _coordinate_boolean_functions(vecfun)
|
||||||
|
|
||||||
|
print(f"\n{name}")
|
||||||
|
print("-" * len(name))
|
||||||
|
|
||||||
|
ais = []
|
||||||
|
|
||||||
|
for i, bf in enumerate(bfs):
|
||||||
|
ai = bf.algebraic_immunity()
|
||||||
|
ais.append(ai)
|
||||||
|
print(f"coordinate {i}: AI = {ai}")
|
||||||
|
|
||||||
|
print(f"\nminimum AI : {min(ais)}")
|
||||||
|
print(f"maximum AI : {max(ais)}")
|
||||||
|
print(f"average AI : {sum(ais)/len(ais):.2f}")
|
||||||
|
|
||||||
|
return ais
|
||||||
|
|
||||||
|
def run_algebraic_immunity():
|
||||||
|
print("Algebraic immunity:")
|
||||||
|
study_algebraic_immunity(F31, "F31")
|
||||||
|
study_algebraic_immunity(F32, "F32")
|
||||||
|
|
||||||
def run_f31f32():
|
def run_f31f32():
|
||||||
|
run_algebraic_immunity()
|
||||||
f31 = _sbox(F31)
|
f31 = _sbox(F31)
|
||||||
f32 = _sbox(F32)
|
f32 = _sbox(F32)
|
||||||
print("\nF31")
|
print("\nF31")
|
||||||
|
|||||||
Reference in New Issue
Block a user