Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/pycrc/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self, width, poly, reflect_in, xor_in, reflect_out, xor_out,
else:
self.crc_shift = 0

self.tbl = self.gen_table()

def __get_nondirect_init(self, init):
"""
return the non-direct init if the direct algorithm has been selected.
Expand Down Expand Up @@ -211,20 +213,18 @@ def table_driven(self, in_data):
if isinstance(in_data, str):
in_data = bytearray(in_data, 'utf-8')

tbl = self.gen_table()

if not self.reflect_in:
reg = self.direct_init << self.crc_shift
for octet in in_data:
tblidx = ((reg >> (self.width - self.tbl_idx_width + self.crc_shift)) ^ octet) & 0xff
reg = ((reg << (self.tbl_idx_width - self.crc_shift)) ^
(tbl[0][tblidx] << self.crc_shift)) & (self.mask << self.crc_shift)
(self.tbl[0][tblidx] << self.crc_shift)) & (self.mask << self.crc_shift)
reg = reg >> self.crc_shift
else:
reg = self.reflect(self.direct_init, self.width)
for octet in in_data:
tblidx = (reg ^ octet) & 0xff
reg = ((reg >> self.tbl_idx_width) ^ tbl[0][tblidx]) & self.mask
reg = ((reg >> self.tbl_idx_width) ^ self.tbl[0][tblidx]) & self.mask
reg = self.reflect(reg, self.width) & self.mask

if self.reflect_out:
Expand Down