Last active
August 18, 2020 22:19
-
-
Save mikeecb/0d510774fb8f1b2aab02e683bb9a6529 to your computer and use it in GitHub Desktop.
Hamming Distance Simplified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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