Initial commit

This commit is contained in:
Qiea
2024-12-22 01:07:54 +08:00
commit 798e299d04
7 changed files with 406 additions and 0 deletions

16
test.py Normal file
View File

@@ -0,0 +1,16 @@
def hamming_distance(hash1, hash2):
# 将哈希值转换为二进制字符串
bin1 = bin(int(hash1, 16))[2:].zfill(len(hash1) * 4) # 16进制转二进制
bin2 = bin(int(hash2, 16))[2:].zfill(len(hash2) * 4)
# 计算汉明距离
return sum(c1 != c2 for c1, c2 in zip(bin1, bin2))
# 给定的两个哈希值
hash1 = 'ffffff7060606000'
hash2 = '000034e3ffffffbf'
# 计算汉明距离
distance = hamming_distance(hash1, hash2)
print(f'汉明距离: {distance}')