Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,54 @@ cdef class SBox(SageObject):
[0 0 2 2 2 2 0 0]
[0 2 2 0 0 2 2 0]
[0 0 0 0 2 2 2 2]
sage: S = SBox(7,4,8,6)
sage: S.difference_distribution_table()
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0]
[0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 2]
[0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0]
TESTS::
Testing square SBoxes::
sage: from sage.crypto.sbox import SBox
sage: S = SBox(7,6,0,4,2,5,1,3)
sage: S.difference_distribution_table()
[8 0 0 0 0 0 0 0]
[0 2 2 0 2 0 0 2]
[0 0 2 2 0 0 2 2]
[0 2 0 2 2 0 2 0]
[0 2 0 2 0 2 0 2]
[0 0 2 2 2 2 0 0]
[0 2 2 0 0 2 2 0]
[0 0 0 0 2 2 2 2]
Testing non-square SBoxes::
sage: from sage.crypto.sbox import SBox
sage: S = SBox(8,8,8,8)
sage: S.difference_distribution_table()
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
sage: S = SBox(7,4,8,6)
sage: S.difference_distribution_table()
[4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0]
[0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 2]
[0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0]
sage: S = SBox(0,0,0,1,0,0,1,3)
sage: S.difference_distribution_table()
[8 0 0 0]
[4 2 2 0]
[2 4 0 2]
[2 4 0 2]
[4 2 2 0]
[6 0 0 2]
[2 4 0 2]
[2 4 0 2]
"""
cdef Py_ssize_t nrows = 1 << self.m
cdef Py_ssize_t ncols = 1 << self.n
Expand All @@ -649,7 +697,7 @@ cdef class SBox(SageObject):
for i in range(nrows):
si = self._S_list[i]
for di in range(nrows):
L[di*nrows + si ^ self._S_list[i ^ di]] += 1
L[di*ncols + si ^ self._S_list[i ^ di]] += 1

A = matrix(ZZ, nrows, ncols, L)
A.set_immutable()
Expand Down