Ask Your Question

Revision history [back]

There is a list of S-Boxes used in cryptographic schemes in the reference manual (including 4x4 ones).

The first one is called Elephant, and can be accessed and used like this:

sage: from sage.crypto.sboxes import sboxes
sage: S = sboxes['Elephant']; S
(14, 13, 11, 0, 2, 1, 4, 15, 7, 10, 8, 5, 9, 12, 3, 6)
sage: S([0,0,0,1])
[1, 1, 0, 1]

You can also create them yourself:

sage: from sage.crypto.sbox import SBox
sage: S = SBox(12,5,6,11,9,0,10,13,3,14,15,8,4,7,1,2)
sage: S.input_size(), S.output_size()
(4, 4)
sage: S([0,0,0,1])
[0, 1, 0, 1]

It is explained on the page S-Boxes and Their Algebraic Representations.