def des.sbox
import bend-osdev-legacy-ciphers@0.1.0.0/des.bend as Desimport Base
import bend-osdev-legacy-ciphers@0.1.0.0/legacy_ciphers.bend as L
177# the S-box entry for 6 bits b1 .. b6: row b1 b6, column b2 b3 b4 b5
178def des.sbox(s: List<&2, U32>, +x: U32) -> U32:
179 +row = U32.or(U32.and(2, U32.shrn(x, 4n)), U32.and(1, x))
180 +col = U32.and(15, U32.shr(x))
181 L.lc.at(s, U32.to_nat(U32.add(U32.mul(row, 16), col)))