for i inrange(1,13): if i <=9: mounth='0'+str(i) else: mounth=str(i) for j inrange(1,32): if j <=9: day='0'+str(j) else: day=str(j) birth='1997'+mounth+day days.append(birth)
code='0175501585710a89h5a60dc9ed2f88d7'
result = {} ratios = []
#碰撞md5,并计算相似值,以字典的形式储存最后读取出相似值最高的值
for day in days: md5 = hashlib.md5(day.encode('utf-8')).hexdigest() seq = difflib.SequenceMatcher(None,md5,code) ratio = seq.ratio() ratios.append(ratio) result[ratio]=day print ratio,day