mirror of
https://github.com/jopohl/urh.git
synced 2026-03-18 22:26:47 +01:00
* add draft for crc configure dialog * add ui file * improve delegate sizing * fix open editors function call placement * consider system font size for optimal editor height * fix font height on windows only as other OSes are fine with default * simplify windows height special case * add draft for crc configure dialog * add ui file * add tab widget to properties dialog + remove unneeded underline fonts * rename type -> field type + add crclabel class * cast labels to crclabel if field type gets changed * dynamic tab creation in label dialog depending on special status labels * integrate CRC widget to dialog * use model for crc data ranges and enhance editor behaviour * move default crc polynomials to class level * make crc polynomial configurable in widget * fix line edit validator + set crc polynomial on combobox change * show crc status in label table * fix unnittest polynomial assignment * Index error catched, when dragging WSP-encoded data into generator * show expected CRC in value table * add action for updating automatically assigned message types * add draft for crc configure dialog * add ui file * add tab widget to properties dialog + remove unneeded underline fonts * rename type -> field type + add crclabel class * cast labels to crclabel if field type gets changed * dynamic tab creation in label dialog depending on special status labels * integrate CRC widget to dialog * use model for crc data ranges and enhance editor behaviour * move default crc polynomials to class level * make crc polynomial configurable in widget * fix line edit validator + set crc polynomial on combobox change * show crc status in label table * fix unnittest polynomial assignment * show expected CRC in value table * add action for updating automatically assigned message types * centralize bit view methods * make start value and final xor configurable * add Checksum Label Type + WSP Checksum subtype * Ensure Start Value and Final XOR have same length as polynomial * pad zeros at front * add crc info label and fix sync between polynomial and xor values * various fixes * test wsp hash functionality * minor fixes * use array.array for parameters to make crcs comparable * integrate crc to generation * add unittest for cc1101 * set wait cursor when extracting archives * remove unneeded status bar in interpretation * set wait cursor when extracting archives in project manager * fix size policy for analysis search line edit * save checksum labels in project * improve alignment * remove double line edit * add test for checksum integration in generator * update coverage * specify coverage format * generate xml coverage report * generate coverage report only for python 3.5 * generate coverage report only for python 3.5 * add variable to control coverage * generate coverage report on success * generate coverage report after success * remove deprecated * add virtualenv opt * use codecov * revert to deprecated * Removed CRC and 'remove_preamble, remove_sync' from CC1101 Data Whitening * repair unittests * fix table copy selection * use plain bits for checksum calculation in generation * add parent
59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
from tests.QtTestCase import QtTestCase
|
|
from urh.signalprocessing.Encoding import Encoding
|
|
from urh.util import util
|
|
from urh.util.GenericCRC import GenericCRC
|
|
from urh.util.WSPChecksum import WSPChecksum
|
|
|
|
|
|
class TestCRC(QtTestCase):
|
|
def setUp(self):
|
|
pass
|
|
|
|
def test_crc(self):
|
|
# http://depa.usst.edu.cn/chenjq/www2/software/crc/CRC_Javascript/CRCcalculation.htm
|
|
# CRC-16: polynomial="16_standard", start_value = False, final_xor = False, reverse_polynomial=False, reverse_all=False
|
|
# CRC-16-CCITT: polynomial="16_ccitt", start_value = False, final_xor = False, reverse_polynomial=False, reverse_all=False
|
|
|
|
# http://www.lammertbies.nl/comm/info/crc-calculation.html <- Fehler
|
|
# CRC-16: polynomial="16_standard", start_value = False, final_xor = False, reverse_polynomial=False, reverse_all=False
|
|
c = GenericCRC(polynomial=WSPChecksum.CRC_8_POLYNOMIAL)
|
|
e = Encoding()
|
|
|
|
bitstr = ["010101010110100111011010111011101110111011100110001011101010001011101110110110101101",
|
|
"010101010110101001101110111011101110111011100110001011101010001011101110110111100101",
|
|
"010101010110100111010010111011101110111011100110001011101010001011101110110110100101"]
|
|
|
|
expected = ["78", "c9", "f2"]
|
|
|
|
for value, expect in zip(bitstr, expected):
|
|
nv = ""
|
|
for i in range(0, len(value)):
|
|
if value[i] == "1":
|
|
nv += "0"
|
|
else:
|
|
nv += "1"
|
|
|
|
self.assertEqual(util.bit2hex(c.crc(e.str2bit(value[4:-8]))), expect)
|
|
|
|
def test_reverse_engineering(self):
|
|
c = GenericCRC(polynomial="16_standard", start_value=False, final_xor=False,
|
|
reverse_polynomial=False, reverse_all=False, lsb_first=False, little_endian=False)
|
|
bitstring_set = [
|
|
"1110001111001011100010000101010100000010110111000101100010100100111110111101100110110111011001010010001011101010",
|
|
"1110010011001011100010000101010100000010110111000101100010100100111110111101100110110111011001010010001011101010",
|
|
"1110010111001011100010000101010100000010110111000101100010100100111110111101100110110111011001010010001011101010",
|
|
"1110011011001011100010000101010100000010110111000101100010100100111110111101100110110111011001010010001011101010"]
|
|
bitset = []
|
|
crcset = []
|
|
|
|
for i in bitstring_set:
|
|
tmp = c.str2bit(i)
|
|
bitset.append(tmp)
|
|
crcset.append(c.crc(tmp))
|
|
|
|
# print(c.guess_standard_parameters(bitset[0], crcset[0]))
|
|
polynomial = c.reverse_engineer_polynomial(bitset, crcset)
|
|
if polynomial:
|
|
self.assertEqual(c.bit2str(polynomial), "1000000000000101")
|
|
self.assertEqual(util.bit2hex(polynomial), "8005")
|