Skip to content

Commit 5093190

Browse files
author
Kazuki Suzuki Przyborowski
authored
Update pycatfile.py
1 parent 79d7b88 commit 5093190

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

pycatfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,17 @@ def SevenZipFileCheck(infile):
14961496
# initial_value can be 0xFFFF or 0x0000
14971497

14981498

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+
14991510
def crc16_ansi(msg, initial_value=0xFFFF):
15001511
# CRC-16-IBM / CRC-16-ANSI polynomial and initial value
15011512
poly = 0x8005 # Polynomial for CRC-16-IBM / CRC-16-ANSI

0 commit comments

Comments
 (0)