Exemplo n.º 1
0
    def test_guess_standard_parameters_and_datarange(self):
        c = GenericCRC(polynomial="16_ccitt", start_value=False, final_xor=False,
                       reverse_polynomial=False, reverse_all=False, lsb_first=False, little_endian=False)
        inpt = "101010101010101010000000111000000000000011100000001011010010110100000000111000000101001010000100000000000100111001111110010000000011011111111001001101100001100010100000000000111011110100010"
        vrfy_crc = "0011101111010001"

        result = c.guess_standard_parameters_and_datarange(c.str2arr(inpt), c.str2arr(vrfy_crc))
        self.assertEqual(result, (2, 84, 172))
        self.assertEqual(vrfy_crc, c.bit2str(c.crc(c.str2arr(inpt[result[1]:result[2]]))))
Exemplo n.º 2
0
    def test_bruteforce_parameters_and_data_range_improved(self):
        c = GenericCRC(polynomial="16_ccitt",
                       start_value=False,
                       final_xor=False,
                       reverse_polynomial=False,
                       reverse_all=False,
                       lsb_first=False,
                       little_endian=False)
        inpt = "101010101010101010000000111000000000000011100000001011010010110100000000111000000101001010000100000000000100111001111110010000000011011111111001001101100001100010100000000000111011110100010"
        vrfy_crc = "0011101111010001"

        t1 = 0
        runs = 100
        for i in range(0, runs):
            t = time.time()
            result = c.bruteforce_parameters_and_data_range(
                c.str2arr(inpt),
                len(inpt) - len(vrfy_crc) - 1)
            t1 += time.time() - t
            # print(result, c.bit2str(c.crc(c.str2arr(inpt[result[1]:result[2]]))))
            self.assertEqual(result[0], 2)  # Parameters = 2
            self.assertEqual(result[1],
                             len(inpt) - 1 - 16 - 88)  # start of datarange
            self.assertEqual(result[2], len(inpt) - 1 - 16)  # end of datarange
            inpt = "0" + inpt if i % 2 == 0 else "1" + inpt
        # print("Performance:", t1/runs)
        self.assertLess(t1 / runs,
                        0.1)  # Should be faster than 100ms in average
Exemplo n.º 3
0
    def test_adaptive_crc_calculation(self):
        c = GenericCRC(polynomial="16_ccitt", start_value=False, final_xor=False,
                       reverse_polynomial=False, reverse_all=False, lsb_first=False, little_endian=False)
        inpt1 = "10101010101010"
        inpt2 = "1010101010101001"

        crc1 = c.crc(c.str2arr(inpt1))
        crc2 = c.crc(c.str2arr(inpt2))

        # Compute crc2 from crc1 in a faster way
        # Note: In general only forward direction
        delta = "01"
        c.start_value = crc1
        crcx = c.crc(c.str2arr(delta))

        self.assertEqual(crcx, crc2)