mirror of
https://github.com/573dev/gfdm-server.git
synced 2026-04-20 16:37:23 -05:00
15 lines
350 B
Python
15 lines
350 B
Python
def calculate_crc8(value: str) -> int:
|
|
"""
|
|
Calculate the CRC8 of a string representation of an int
|
|
"""
|
|
crc = 0
|
|
|
|
for c in bytearray(value.encode("ASCII")):
|
|
for i in range(8, 0, -1):
|
|
t = c ^ crc
|
|
crc >>= 1
|
|
if (t & 0x01) != 0:
|
|
crc ^= 0x8C
|
|
c >>= 1
|
|
return crc
|