Skip to content

Commit

Permalink
Update pyarchivefile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski authored Feb 14, 2025
1 parent f19938a commit 886e80c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyarchivefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,17 @@ def SevenZipFileCheck(infile):
# initial_value can be 0xFFFF or 0x0000


def crc_calculate(msg, poly, initial_value, bit_length):
"""Generic CRC calculation function."""
crc = initial_value
for byte in msg:
crc ^= byte << (bit_length - 8)
for _ in range(8):
crc = (crc << 1) ^ poly if crc & (1 << (bit_length - 1)) else crc << 1
crc &= (1 << bit_length) - 1
return crc


def crc16_ansi(msg, initial_value=0xFFFF):
# CRC-16-IBM / CRC-16-ANSI polynomial and initial value
poly = 0x8005 # Polynomial for CRC-16-IBM / CRC-16-ANSI
Expand Down

0 comments on commit 886e80c

Please sign in to comment.