# SAGEMATH FAILS to compute Difference Distribution Table for rectangular SBOX of logical AND, I don't know why

I was being paranoid about some calculations I did so I started review one by one with the aid of software.

Considere the rectangular SBOX = [0,0,0,1], as you may see this is the SBOX for AND or at least I wanted it to be so. I computed its LAT (linear approximation table) and DDT(difference distribution table) and I wanted to check the results with Sagemath.

For the LAT, response is coherent and adequate with what I had and what I expected:

sage: S = SBox(0,0,0,1)
sage: S.linear_approximation_table(scale="correlation")
[   1  1/2]
[   0  1/2]
[   0  1/2]
[   0 -1/2]


For DDT the system breaks as you see here:

sage: S = SBox(0,0,0,1)
sage: S.difference_distribution_table()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[84], line 1
----> 1 S.difference_distribution_table()

File /usr/lib64/python3.11/site-packages/sage/misc/cachefunc.pyx:2297, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__()
2295 if self.cache is None:
2296     f = self.f
-> 2297     self.cache = f(self._instance)
2298 return self.cache
2299

File /usr/lib64/python3.11/site-packages/sage/crypto/sbox.pyx:652, in sage.crypto.sbox.SBox.difference_distribution_table()
650     si = self._S_list[i]
651     for di in range(nrows):
--> 652         L[di*nrows + si ^ self._S_list[i ^ di]] += 1
653
654 A = matrix(ZZ, nrows, ncols, L)

IndexError: list index out of range
sage:


What is happening? I personally can't make sense of it.

ps I tried this workaround that I think it will do the job:

sage: S = SBox(0,0,0,2)
sage: S.difference_distribution_table()
[4 0 0 0]
[2 0 2 0]
[2 0 2 0]
[2 0 2 0]
sage:


But I really don't like it at all. Thank you in advance for answers.

edit retag close merge delete