本文整理汇总了Python中crc_algorithms.Crc.reflect方法的典型用法代码示例。如果您正苦于以下问题:Python Crc.reflect方法的具体用法?Python Crc.reflect怎么用?Python Crc.reflect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crc_algorithms.Crc
的用法示例。
在下文中一共展示了Crc.reflect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_file
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import reflect [as 别名]
def check_file(opt):
"""
Calculate the CRC of a file.
This algorithm uses the table_driven CRC algorithm.
"""
if opt.undefined_crc_parameters:
sys.stderr.write("{0:s}: error: undefined parameters\n".format(sys.argv[0]))
sys.exit(1)
alg = Crc(
width=opt.width, poly=opt.poly,
reflect_in=opt.reflect_in, xor_in=opt.xor_in,
reflect_out=opt.reflect_out, xor_out=opt.xor_out,
table_idx_width=opt.tbl_idx_width)
if not opt.reflect_in:
register = opt.xor_in
else:
register = alg.reflect(opt.xor_in, opt.width)
try:
with open(opt.check_file, 'rb') as f:
check_bytes = bytearray(f.read(1024))
while check_bytes != b"":
register = crc_file_update(alg, register, check_bytes)
check_bytes = bytearray(f.read(1024))
except IOError:
sys.stderr.write(
"{0:s}: error: can't open file {1:s}\n".format(sys.argv[0], opt.check_file))
sys.exit(1)
if opt.reflect_out:
register = alg.reflect(register, opt.width)
register = register ^ opt.xor_out
return register
示例2: check_file
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import reflect [as 别名]
def check_file(opt):
"""
Calculate the CRC of a file.
This algorithm uses the table_driven CRC algorithm.
"""
if opt.UndefinedCrcParameters:
sys.stderr.write("%s: error: undefined parameters\n" % sys.argv[0])
sys.exit(1)
alg = Crc(width = opt.Width, poly = opt.Poly,
reflect_in = opt.ReflectIn, xor_in = opt.XorIn,
reflect_out = opt.ReflectOut, xor_out = opt.XorOut,
table_idx_width = opt.TableIdxWidth)
try:
in_file = open(opt.CheckFile, 'rb')
except IOError:
sys.stderr.write("%s: error: can't open file %s\n" % (sys.argv[0], opt.CheckFile))
sys.exit(1)
if not opt.ReflectIn:
register = opt.XorIn
else:
register = alg.reflect(opt.XorIn, opt.Width)
# Read bytes from the file.
check_bytes = in_file.read(1024)
while check_bytes:
register = crc_file_update(alg, register, check_bytes)
check_bytes = in_file.read(1024)
in_file.close()
if opt.ReflectOut:
register = alg.reflect(register, opt.Width)
register = register ^ opt.XorOut
return register
示例3: __get_init_value
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import reflect [as 别名]
def __get_init_value(self):
"""
Return the init value of a C implementation, according to the selected algorithm and
to the given options.
If no default option is given for a given parameter, value in the cfg_t structure must be used.
"""
if self.opt.Algorithm == self.opt.Algo_Bit_by_Bit:
if self.opt.XorIn == None or self.opt.Width == None or self.opt.Poly == None:
return None
crc = Crc(
width=self.opt.Width,
poly=self.opt.Poly,
reflect_in=self.opt.ReflectIn,
xor_in=self.opt.XorIn,
reflect_out=self.opt.ReflectOut,
xor_out=self.opt.XorOut,
table_idx_width=self.opt.TableIdxWidth,
)
init = crc.NonDirectInit
elif self.opt.Algorithm == self.opt.Algo_Bit_by_Bit_Fast:
if self.opt.XorIn == None:
return None
init = self.opt.XorIn
elif self.opt.Algorithm == self.opt.Algo_Table_Driven:
if self.opt.ReflectIn == None or self.opt.XorIn == None or self.opt.Width == None:
return None
if self.opt.Poly == None:
poly = 0
else:
poly = self.opt.Poly
crc = Crc(
width=self.opt.Width,
poly=poly,
reflect_in=self.opt.ReflectIn,
xor_in=self.opt.XorIn,
reflect_out=self.opt.ReflectOut,
xor_out=self.opt.XorOut,
table_idx_width=self.opt.TableIdxWidth,
)
if self.opt.ReflectIn:
init = crc.reflect(crc.DirectInit, self.opt.Width)
else:
init = crc.DirectInit
else:
init = 0
return self.__pretty_hex(init, self.opt.Width)