We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 79d7b88 commit 5093190Copy full SHA for 5093190
1 file changed
pycatfile.py
@@ -1496,6 +1496,17 @@ def SevenZipFileCheck(infile):
1496
# initial_value can be 0xFFFF or 0x0000
1497
1498
1499
+def crc_calculate(msg, poly, initial_value, bit_length):
1500
+ """Generic CRC calculation function."""
1501
+ crc = initial_value
1502
+ for byte in msg:
1503
+ crc ^= byte << (bit_length - 8)
1504
+ for _ in range(8):
1505
+ crc = (crc << 1) ^ poly if crc & (1 << (bit_length - 1)) else crc << 1
1506
+ crc &= (1 << bit_length) - 1
1507
+ return crc
1508
+
1509
1510
def crc16_ansi(msg, initial_value=0xFFFF):
1511
# CRC-16-IBM / CRC-16-ANSI polynomial and initial value
1512
poly = 0x8005 # Polynomial for CRC-16-IBM / CRC-16-ANSI
0 commit comments