To generate the same numeric value across all Python versions and platforms, use crc32(data) & 0xffffffff. If you are only using the checksum in packed binary format this is not necessary as the return value is the correct 32-bit binary representation regardless of sign.
std = '4D1FAE0B'.lower() for year in range(1500,3000): for month in range(1,13): for day in range(1,32): syyyy = str(year) smm = str(month) if month < 10: smm = '0' + smm sdd = str(day) if day < 10: sdd = '0' + sdd now = syyyy + smm + sdd if crc32(now) == std: print(now)
import zlib def crc32(st): crc = zlib.crc32(st.encode('utf-8')) if crc > 0: return "%x" % (crc & 0xffffffff) else: return "%x" % (crc & 0xffffffff) #生成年'1000'~'3000' year = [str(i) for i in range(1000,3000)] #生成月'01'~'12' month = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,13) ] #生成日'01'~'31' day = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,32) ] #题目所给 realDate = '4D1FAE0B'.lower() #穷举日期计算crc32值然后与题目给的值进行比对,一样则输出 import itertools #利用itertools.product()生成年月日的所有组合 for item in itertools.product(year,month,day): date = ''.join(item) if crc32(date) == realDate: print(date)