当前位置: 首页>>代码示例>>Python>>正文


Python Crc.reflect方法代码示例

本文整理汇总了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
开发者ID:pombredanne,项目名称:pycrc,代码行数:36,代码来源:pycrc.py

示例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
开发者ID:byronduenas,项目名称:cpen442,代码行数:36,代码来源:modified_pycrc.py

示例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)
开发者ID:TechJect,项目名称:pycrc,代码行数:48,代码来源:crc_symtable.py


注:本文中的crc_algorithms.Crc.reflect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。