示例#1
0
 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)
示例#2
0
    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)
示例#3
0
    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))
示例#4
0
    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))
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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))
示例#11
0
 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))