def test_chi(self): a = StateArray(initialstate) at = chi(a) #Checking x = 0 for every row for y, z in itertools.product(range(5), range(a.w)): val = (not a.bit(1, y, z)) and (a.bit(2, y, z)) self.assertEqual(at.bit(0, y, z), a.bit(0, y, z) ^ val)
def __call__(self, s): assert len(s) == self.b #passo 1 a = StateArray(s) l = int(log(a.w, 2)) i = 0 #passo 2 for ir in range(2 * l + 12 - self.nr, 2 * l + 12): a = Rnd(a, ir) #passo 3 e 4 return a.bits
def test_ro(self): a = StateArray(initialstate) at = ro(a) offsets = [[0, 36, 3, 105, 210], [1, 300, 10, 45, 66], [190, 6, 171, 15, 253], [28, 55, 153, 21, 120], [91, 276, 231, 136, 78]] for x in range(5): for y in range(5): offset = offsets[x][y] for z in range(a.w): self.assertEqual(a.bit(x, y, z), at.bit(x, y, (z + offset) % at.w))
def test_iota(self): a = StateArray(initialstate) #iota should NOT affect any lane beyond 0,0 at = iota(a, 0) for x, y in itertools.product(range(5), range(5)): if x != 0 or y != 0: self.assertEqual(at.lane(x, y), a.lane(x, y)) for ir in range(24): at = iota(a, ir) truncRC = BitArray(RC[ir]) truncRC.reverse() truncRC = truncRC[:a.w] self.assertEqual(at.lane(0, 0), a.lane(0, 0) ^ truncRC)
def test_theta(self): a = StateArray(initialstate) at = theta(a) x = 3 y = 2 z = 1 c1 = a.bit(x-1,0,z) \ ^ a.bit(x-1,1,z) \ ^ a.bit(x-1,2,z) \ ^ a.bit(x-1,3,z) \ ^ a.bit(x-1,4,z) c2 = a.bit(x+1,0,z-1) \ ^ a.bit(x+1,1,z-1) \ ^ a.bit(x+1,2,z-1) \ ^ a.bit(x+1,3,z-1) \ ^ a.bit(x+1,4,z-1) expected = a.bit(x, y, z) ^ c1 ^ c2 self.assertEqual(at.bit(x, y, z), expected)
def test_pi(self): a = StateArray(initialstate) at = pi(a) for x, y in itertools.product(range(5), range(5)): self.assertEqual(at.lane(x, y), a.lane((x + 3 * y) % 5, x))