Further optimisations in ChkSum.
This commit is contained in:
parent
155d0e023c
commit
0c9528fd4f
@ -4,16 +4,12 @@ class ChkSum:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.chksum = 0
|
self.chksum = 0
|
||||||
self.chksum_without_last = 0
|
|
||||||
self.last_byte = 0xff
|
self.last_byte = 0xff
|
||||||
|
|
||||||
def add(self, data):
|
def add(self, data):
|
||||||
for c in data[:-1]:
|
for c in data:
|
||||||
self.chksum += c
|
self.chksum += c
|
||||||
self.chksum_without_last = self.chksum
|
|
||||||
self.chksum_without_last &= 0xff
|
|
||||||
self.last_byte = data[-1]
|
self.last_byte = data[-1]
|
||||||
self.chksum += self.last_byte
|
|
||||||
self.chksum &= 0xff
|
self.chksum &= 0xff
|
||||||
|
|
||||||
def add_from_file(self, filename: str, print_progress: bool = False, blocksize: int=16384):
|
def add_from_file(self, filename: str, print_progress: bool = False, blocksize: int=16384):
|
||||||
@ -38,7 +34,8 @@ class ChkSum:
|
|||||||
return (self.chksum == 0)
|
return (self.chksum == 0)
|
||||||
|
|
||||||
def get_expected(self):
|
def get_expected(self):
|
||||||
expected = ( 0x100 - self.chksum_without_last ) & 0xff
|
chksum_without_last = ( 0x100 + self.chksum - self.last_byte ) & 0xff
|
||||||
|
expected = ( 0x100 - chksum_without_last ) & 0xff
|
||||||
return expected
|
return expected
|
||||||
|
|
||||||
def get_last_byte(self):
|
def get_last_byte(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user