User:David MacQuigg/Sandbox/S-box (cryptography)

An S-box (Substitution box) is is a common component in cryptographic systems. It is fast, versatile, and easily implemented in both hardware and software. An "m by n" S-box can take any bit pattern on its m inputs, and transform it to any desired bit pattern on its n outputs. Thus, the function implemented by this S-box can have M = 2**m possible inputs, and N = 2**n possible outputs. Since there can be only one output for any given input, the total number of functions possible is N**M (10**16 for an 8 by 8 S-box).

In hardware, an S-box can be implemented very compactly as PLA (Programmable Logic Array). In software, an S-box is just an array of integers: S4x4 = [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7] # 4 by 4 S-box The integers in this example are just a permutation of all possible 4-bit outputs {0, 1, 2, ... 15}. Restricting