mirror of
https://github.com/perfect-dark-pc-port/perfect_dark.git
synced 2026-10-24 00:02:43 +02:00
port: net: replace useless checksum with slightly more useful crc16
This commit is contained in:
1 parent
562e763fbd
commit
4cb99506cb
2 files changed
+12
-6
No files matched your search
+6
-3
@@ -9,10 +9,13 @@ QUERY_MAGIC = b"PDQM\x01"
|
||||
MAX_WAIT = 5.0
|
||||
|
||||
def checksum(data):
|
||||
chk = 1
|
||||
crc = 0xFFFF
|
||||
for b in data[:-2]:
|
||||
chk = (chk + b) % 65521
|
||||
return chk
|
||||
x = crc >> 8 ^ b
|
||||
x ^= x >> 4
|
||||
crc += (crc << 8) ^ (x << 12) ^ (x << 5) ^ x
|
||||
crc &= 0xFFFF
|
||||
return crc
|
||||
|
||||
def eat_string(data):
|
||||
strlen = struct.unpack_from("<H", data)[0]
|
||||
|
||||
Reference in new issue
Block a user