Skip to content

Commit

Permalink
Factor out reflectIn(), reflectOut() methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Mar 21, 2018
1 parent 7253748 commit 9f0e189
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pyxcp/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,21 @@ def __init__(self, table, initalRemainder, finalXorValue, reflectData, reflectRe
def __call__(self, frame):
remainder = self.initalRemainder
for ch in frame:
if self.reflectData:
data = (reflect(ch, 8) ^ (remainder >> (self.WIDTH - 8))) & 0xff
else:
data = (ch ^ (remainder >> (self.WIDTH - 8))) & 0xff
data = self.reflectIn(ch, remainder)
remainder = (self.table[data] ^ (remainder << 8)) & 0xffff
return self.reflectOut(remainder)

def reflectIn(self, ch, remainder):
if self.reflectData:
return (reflect(ch, 8) ^ (remainder >> (self.WIDTH - 8))) & 0xff
else:
return (ch ^ (remainder >> (self.WIDTH - 8))) & 0xff

def reflectOut(self, remainder):
if self.reflectRemainder:
result = (reflect(remainder, 16) ^ self.finalXorValue)
return reflect(remainder, 16) ^ self.finalXorValue
else:
result = remainder ^ self.finalXorValue
return result
return remainder ^ self.finalXorValue


"""
Expand Down

0 comments on commit 9f0e189

Please sign in to comment.