當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。