Skip to content

Instantly share code, notes, and snippets.

@codl
Last active April 11, 2017 20:35
Show Gist options
  • Select an option

  • Save codl/7eb869e96fa55a2805594ad60acf0544 to your computer and use it in GitHub Desktop.

Select an option

Save codl/7eb869e96fa55a2805594ad60acf0544 to your computer and use it in GitHub Desktop.
whoops lol
import hashlib
import random
import matplotlib.pyplot as plt
DOMAIN_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz-."
def make_random_md5s(count, prefix=""):
sets = []
for _ in range(count):
inputt = prefix
for _ in range(15): # im gonna assume 15 chars is average domain length
inputt += random.choice(DOMAIN_CHARS)
sets += [(inputt, hashlib.md5(bytes(inputt, "UTF-8")).hexdigest()[:6])]
return sets
if __name__ == "__main__":
print("generating 100k md5s with https:// prefix")
with_prefix = make_random_md5s(100000, "https://")
print("samples:", with_prefix[:2])
print("generating 100k md5s without prefix")
without_prefix = make_random_md5s(100000, "")
print("samples:", without_prefix[:2])
print("converting md5s to integers")
prefix_values = list(int(t[1], 16) for t in with_prefix)
noprefix_values = list(int(t[1], 16) for t in without_prefix)
print("samples:", prefix_values[0], noprefix_values[0])
plt.hist((prefix_values, noprefix_values))
plt.legend(("with https://", "without a prefix"))
plt.gca().get_xaxis().get_major_formatter().set_scientific(False);
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment