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
def test_bruteforce_parameters_and_data_range(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.bruteforce_parameters_and_data_range( c.str2arr(inpt), len(inpt) - len(vrfy_crc) - 1) self.assertEqual(result, (2, 84, 172)) self.assertEqual( vrfy_crc, c.bit2str(c.crc(c.str2arr(inpt[result[1]:result[2]]))))