# -*- coding: Latin-1 -*- from crc24 import Options from crc24_algorithms import Crc # function check_string ############################################################################### def check_string(myString): opt=Options("0.6.4") opt.CheckString=myString """ Returns the calculated CRC sum of a string """ if opt.UndefinedCrcParameters: sys.stderr.write("Error: undefined parameters\n") 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(opt) crc = this_crc = None if opt.Algorithm & opt.Algo_Bit_by_Bit: this_crc = alg.bit_by_bit(opt.CheckString) if crc != None and this_crc != crc: sys.stderr.write("Error: different checksums: 0x%x, 0x%x\n" % (this_crc, crc)) sys.exit(1) crc = this_crc if opt.Algorithm & opt.Algo_Bit_by_Bit_Fast: this_crc = alg.bit_by_bit_fast(opt.CheckString) if crc != None and this_crc != crc: sys.stderr.write("Error: different checksums: 0x%x, 0x%x\n" % (this_crc, crc)) sys.exit(1) crc = this_crc if opt.Algorithm & opt.Algo_Table_Driven: opt.TableIdxWidth = 8 # FIXME cowardly refusing to use less bits for the table this_crc = alg.table_driven(opt.CheckString) if crc != None and this_crc != crc: sys.stderr.write("Error: different checksums: 0x%x, 0x%x\n" % (this_crc, crc)) sys.exit(1) crc = this_crc return crc