本文整理汇总了Python中crc_algorithms.Crc.table_driven方法的典型用法代码示例。如果您正苦于以下问题:Python Crc.table_driven方法的具体用法?Python Crc.table_driven怎么用?Python Crc.table_driven使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crc_algorithms.Crc
的用法示例。
在下文中一共展示了Crc.table_driven方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
def main():
string1 = ''
string2 = "c651ceb5fa05b4195f993513d8bb5381"
crc = Crc(width = 16, poly = 0x8005,
reflect_in = True, xor_in = 0x0000,
reflect_out = True, xor_out = 0x0000)
crc1 = 'a'
crc2 = crc.table_driven(string2)
print datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
while crc1 != crc2:
string1 = ''.join(random.SystemRandom().choice(string.ascii_letters + \
string.digits) for _ in range(32))
crc1 = crc.table_driven(string1)
print datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
print string1
print string2
print "CRC: " + str(crc1)
示例2: check_string
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
def check_string(opt):
"""
Return the calculated CRC sum of a string.
"""
error = False
if opt.UndefinedCrcParameters:
sys.stderr.write("%s: error: undefined parameters\n" % sys.argv[0])
sys.exit(1)
#print(opt.Algorithm)
if opt.Algorithm == 0:
opt.Algorithm = opt.Algo_Bit_by_Bit | opt.Algo_Bit_by_Bit_Fast | opt.Algo_Table_Driven
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)
opt.Algorithm = opt.Algo_Table_Driven
crc = None
if opt.Algorithm & opt.Algo_Bit_by_Bit:
#print( "bit_by_bit")
bbb_crc = alg.bit_by_bit(opt.CheckString)
if crc != None and bbb_crc != crc:
error = True
crc = bbb_crc
if opt.Algorithm & opt.Algo_Bit_by_Bit_Fast:
bbf_crc = alg.bit_by_bit_fast(opt.CheckString)
#print( "bit_by_bit_fast")
if crc != None and bbf_crc != crc:
error = True
crc = bbf_crc
if opt.Algorithm & opt.Algo_Table_Driven:
# no point making the python implementation slower by using less than 8 bits as index.
opt.TableIdxWidth = 8
tbl_crc = alg.table_driven(opt.CheckString)
if crc != None and tbl_crc != crc:
error = True
crc = tbl_crc
if error:
sys.stderr.write("%s: error: different checksums!\n" % sys.argv[0])
if opt.Algorithm & opt.Algo_Bit_by_Bit:
sys.stderr.write(" bit-by-bit: 0x%x\n" % bbb_crc)
if opt.Algorithm & opt.Algo_Bit_by_Bit_Fast:
sys.stderr.write(" bit-by-bit-fast: 0x%x\n" % bbf_crc)
if opt.Algorithm & opt.Algo_Table_Driven:
sys.stderr.write(" table_driven: 0x%x\n" % tbl_crc)
sys.exit(1)
return crc
示例3: check_string
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
def check_string(opt):
"""
Return the calculated CRC sum of a string.
"""
error = False
if opt.undefined_crc_parameters:
sys.stderr.write("{0:s}: error: undefined parameters\n".format(sys.argv[0]))
sys.exit(1)
if opt.algorithm == 0:
opt.algorithm = opt.algo_bit_by_bit | opt.algo_bit_by_bit_fast | opt.algo_table_driven
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)
crc = None
if opt.algorithm & opt.algo_bit_by_bit:
bbb_crc = alg.bit_by_bit(opt.check_string)
if crc != None and bbb_crc != crc:
error = True
crc = bbb_crc
if opt.algorithm & opt.algo_bit_by_bit_fast:
bbf_crc = alg.bit_by_bit_fast(opt.check_string)
if crc != None and bbf_crc != crc:
error = True
crc = bbf_crc
if opt.algorithm & opt.algo_table_driven:
# no point making the python implementation slower by using less than 8 bits as index.
opt.tbl_idx_width = 8
tbl_crc = alg.table_driven(opt.check_string)
if crc != None and tbl_crc != crc:
error = True
crc = tbl_crc
if error:
sys.stderr.write("{0:s}: error: different checksums!\n".format(sys.argv[0]))
if opt.algorithm & opt.algo_bit_by_bit:
sys.stderr.write(" bit-by-bit: {0:#x}\n".format(bbb_crc))
if opt.algorithm & opt.algo_bit_by_bit_fast:
sys.stderr.write(" bit-by-bit-fast: {0:#x}\n".format(bbf_crc))
if opt.algorithm & opt.algo_table_driven:
sys.stderr.write(" table_driven: {0:#x}\n".format(tbl_crc))
sys.exit(1)
return crc
示例4: __get_crc
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
def __get_crc(self, model, check_str = "123456789", expected_crc = None):
"""
Get the CRC for a set of parameters from the Python reference implementation.
"""
if self.verbose:
out_str = "Crc(width = %(width)d, poly = 0x%(poly)x, reflect_in = %(reflect_in)s, xor_in = 0x%(xor_in)x, reflect_out = %(reflect_out)s, xor_out = 0x%(xor_out)x)" % model
if expected_crc is not None:
out_str += " [check = 0x%x]" % expected_crc
print(out_str)
alg = Crc(width = model["width"], poly = model["poly"],
reflect_in = model["reflect_in"], xor_in = model["xor_in"],
reflect_out = model["reflect_out"], xor_out = model["xor_out"])
error = False
crc = expected_crc
if self.use_algo_bit_by_bit:
bbb_crc = alg.bit_by_bit(check_str)
if crc is None:
crc = bbb_crc
error = error or bbb_crc != crc
if self.use_algo_bit_by_bit_fast:
bbf_crc = alg.bit_by_bit_fast(check_str)
if crc is None:
crc = bbf_crc
error = error or bbf_crc != crc
if self.use_algo_table_driven:
tbl_crc = alg.table_driven(check_str)
if crc is None:
crc = tbl_crc
error = error or tbl_crc != crc
if error:
print("error: different checksums!")
if expected_crc is not None:
print(" check: 0x%x" % expected_crc)
if self.use_algo_bit_by_bit:
print(" bit-by-bit: 0x%x" % bbb_crc)
if self.use_algo_bit_by_bit_fast:
print(" bit-by-bit-fast: 0x%x" % bbf_crc)
if self.use_algo_table_driven:
print(" table_driven: 0x%x" % tbl_crc)
return None
return crc
示例5: __get_crc
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
def __get_crc(self, model, check_str = '123456789', expected_crc = None):
"""
Get the CRC for a set of parameters from the Python reference implementation.
"""
if self.verbose:
out_str = 'Crc(width = {width:d}, poly = {poly:#x}, reflect_in = {reflect_in}, xor_in = {xor_in:#x}, reflect_out = {reflect_out}, xor_out = {xor_out:#x})'.format(**model)
if expected_crc is not None:
out_str += ' [check = {0:#x}]'.format(expected_crc)
print(out_str)
alg = Crc(width = model['width'], poly = model['poly'],
reflect_in = model['reflect_in'], xor_in = model['xor_in'],
reflect_out = model['reflect_out'], xor_out = model['xor_out'])
error = False
crc = expected_crc
if self.use_algo_bit_by_bit:
bbb_crc = alg.bit_by_bit(check_str)
if crc is None:
crc = bbb_crc
error = error or bbb_crc != crc
if self.use_algo_bit_by_bit_fast:
bbf_crc = alg.bit_by_bit_fast(check_str)
if crc is None:
crc = bbf_crc
error = error or bbf_crc != crc
if self.use_algo_table_driven:
tbl_crc = alg.table_driven(check_str)
if crc is None:
crc = tbl_crc
error = error or tbl_crc != crc
if error:
print('error: different checksums!')
if expected_crc is not None:
print(' check: {0:#x}'.format(expected_crc))
if self.use_algo_bit_by_bit:
print(' bit-by-bit: {0:#x}'.format(bbb_crc))
if self.use_algo_bit_by_bit_fast:
print(' bit-by-bit-fast: {0:#x}'.format(bbf_crc))
if self.use_algo_table_driven:
print(' table_driven: {0:#x}'.format(tbl_crc))
return None
return crc
示例6: __init__
# 需要导入模块: from crc_algorithms import Crc [as 别名]
# 或者: from crc_algorithms.Crc import table_driven [as 别名]
#.........这里部分代码省略.........
opos = pos
pos += 1
ls = s
# -------------------------------------------------------------------
def read_bytes(self, clkpos, b):
bit = 7
char = 0
data = [ 0xa1 ]
cellmark = 1
crcok = False
crc = 0
while b > 0:
# prepare 0, +1 and +2 clocks
clk0 = self.clock[clkpos]
clk1 = self.clock[clkpos+1]
clk2 = self.clock[clkpos+2]
# mark cell start
self.samples[clk0][3] = cellmark
cellmark *= -1
# mark bit end
self.samples[clk2][4] = 1
self.samples[clk2][5] = self.samples[clk1][0]
# shift bit value into the byte
char |= self.samples[clk1][0] << bit
bit -= 1
if bit < 0:
# append only data, not CRC
if b > 2:
data.append(char)
elif b == 2:
crc = self.crc.table_driven(''.join([chr(x) for x in data]))
print "%x" % crc
if char == (crc & 0xff00) >> 8:
self.samples[clk2][8] = 1
crcok = True
else:
self.samples[clk2][8] = 2
crcok = False
elif b == 1:
if char == crc & 0xff:
self.samples[clk2][8] = 1
crcok &= True
else:
self.samples[clk2][8] = 2
crcok = False
# mark and store byte
self.samples[clk2][6] = 1
self.samples[clk2][7] = char
bit = 7
b -= 1
char = 0
clkpos += 2
self.samples[clk2][3] = 2
return data, crcok
# -------------------------------------------------------------------
def analyze(self, clock, margin, offset):
self.gaps = []
self.gap_hist = {}
self.clock = []
self.a1 = []
print "Regenerating clock..."
self.clock_regen(clock, margin, offset)
print "Analyzing signal gaps..."
self.calc_gaps()
print "Looking for sector header/data marks..."
self.a1_search()
print "%i A1 marks found." % len(self.a1)
print "Analyzing sectors..."
count = 0
while count < len(self.a1):
try:
data, crcok = self.read_bytes(self.a1[count]+1, 6)
print ''.join([chr(x) for x in data])
print "---- CRC: %s --------------------------------------------------------" % str(crcok)
except Exception, e:
print str(e)
pass
count += 1
try:
data, crcok = self.read_bytes(self.a1[count]+1, 512 + 3)
print ''.join([chr(x) for x in data])
print "---- CRC: %s --------------------------------------------------------" % str(crcok)
except Exception, e:
print str(e)
pass
count += 1