Esempio n. 1
0
    def test_decode(self):
        for code, rolling, fixed in zip(self.v1_codes, self.v1_rolling_list,
                                        self.v1_fixed_list):
            code = [int(bit) for bit in code]
            rolling_out, fixed_out = secplus.decode(code)

            self.assertEqual(rolling, rolling_out)
            self.assertEqual(fixed, fixed_out)
Esempio n. 2
0
    def process_buffer(self):
        if self.buffer[0] == 0:
            self.pair = self.buffer[1:21]
        elif len(self.pair) == 20 and self.buffer[0] == 2:
            self.pair += self.buffer[1:21]

        if len(self.pair) == 40 and self.pair != self.last_pair:
            rolling, fixed = secplus.decode(self.pair)
            print secplus.pretty(rolling, fixed)
            self.last_pair = self.pair
Esempio n. 3
0
    def test_encode_decode(self):
        for _ in range(20000):
            rolling = random.randrange(2**32) & 0xfffffffe
            fixed = random.randrange(3**20)

            rolling_out, fixed_out = secplus.decode(
                secplus.encode(rolling, fixed))

            self.assertEqual(rolling, rolling_out)
            self.assertEqual(fixed, fixed_out)
Esempio n. 4
0
 def test_decode_robustness(self):
     for _ in range(20000):
         random_code = [random.randrange(3) for _ in range(40)]
         rolling, fixed = secplus.decode(random_code)
         self.assertLess(rolling, 2**32)
         self.assertLess(fixed, 3**20)