Last active
August 18, 2020 22:19
-
-
Save mikeecb/a4c988da9a2931e6b0c82af086dc01cb to your computer and use it in GitHub Desktop.
Key Size 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
b = bytearray("".join(list(open("6.txt", "r"))).decode("base64")) | |
normalized_distances = [] | |
for KEYSIZE in range(2, 40): | |
b1 = b[:KEYSIZE] | |
b2 = b[KEYSIZE:KEYSIZE*2] | |
b3 = b[KEYSIZE*2:KEYSIZE*3] | |
b4 = b[KEYSIZE*3:KEYSIZE*4] | |
normalized_distance = float( | |
hamming_distance(b1, b2) + | |
hamming_distance(b2, b3) + | |
hamming_distance(b3, b4) | |
) / (KEYSIZE * 3) | |
normalized_distances.append( | |
(KEYSIZE, normalized_distance) | |
) | |
normalized_distances = sorted(normalized_distances, key=lambda (_, y): y) | |
# [(2, 2.0), (3, 2.6666666666666665), (29, 2.793103448275862), ...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment