From d7bdfd250294d73ee8980f73de3591dc09e35ca8 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Mon, 6 Jul 2026 11:28:20 +0200 Subject: [PATCH] document lookup table --- src/tea3/lut.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tea3/lut.py b/src/tea3/lut.py index 526fcbe..30c23ae 100644 --- a/src/tea3/lut.py +++ b/src/tea3/lut.py @@ -1,6 +1,12 @@ from typing import Callable def pack_lut_4(f: Callable[..., int], order: tuple[int, int, int, int] = (0, 1, 2, 3)) -> int: + """ + Pack a 4-input Boolean function into a 16-bit LUT (Look-Up Table). + + The function is evaluated for all 16 input combinations, and the result for input index ``i`` is stored in bit ``i`` of the returned integer. + The ``order`` parameter specifies how the input bits of the LUT index are mapped to the arguments of ``f``, allowing input permutations. + """ lut = 0 for idx in range(16): bits = [(idx >> i) & 1 for i in range(4)] # b0, b1, b2, b3 @@ -63,6 +69,9 @@ def F32_7(x0, x1, y0, y1): return (x0 & x1 & y1) ^ (x0 & y0 & y1) ^ (x0 & y0) ^ (x1 & y0 & y1) ^ x1 ^ y0 ^ y1 ^ 1 def main(): + """ + Derive TEA3 Look-Up Tables from F31 and F32 definitions. + """ F31_orders = [ (0, 1, 2, 3), (0, 1, 2, 3),