Skip to content

Instantly share code, notes, and snippets.

@mikeecb
Last active August 18, 2020 22:19
Show Gist options
  • Save mikeecb/0d510774fb8f1b2aab02e683bb9a6529 to your computer and use it in GitHub Desktop.
Save mikeecb/0d510774fb8f1b2aab02e683bb9a6529 to your computer and use it in GitHub Desktop.
Hamming Distance Simplified
def hamming_distance(enc_str1, enc_str2):
differing_bits = 0
for byte in xor(b1, b2):
differing_bits += bin(byte).count("1")
return differing_bits
b1 = bytearray("this is a test")
b2 = bytearray("wokka wokka!!!")
hamming_distance(b1, b2)
# 37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment