Created
May 2, 2020 17:27
-
-
Save EffectRenan/2425aa1ab52e35f6f8ee8b31b2582d65 to your computer and use it in GitHub Desktop.
MD5 collision
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
# -*- coding: utf-8 -*- | |
import multiprocessing | |
import hashlib | |
import random | |
import string | |
import sys | |
CHARS = string.letters + string.digits | |
def cmp_md5(substr, stop_event, str_len, start=0, size=20): | |
global CHARS | |
while not stop_event.is_set(): | |
rnds = ''.join(random.choice(CHARS) for _ in range(size)) | |
md5 = hashlib.md5(rnds) | |
if md5.hexdigest()[start: start+str_len] == substr: | |
print rnds | |
stop_event.set() | |
if __name__ == '__main__': | |
substr = sys.argv[1].strip() | |
start_pos = int(sys.argv[2]) if len(sys.argv) > 1 else 0 | |
str_len = len(substr) | |
cpus = multiprocessing.cpu_count() | |
stop_event = multiprocessing.Event() | |
processes = [multiprocessing.Process(target=cmp_md5, args=(substr, | |
stop_event, str_len, start_pos)) | |
for i in range(cpus)] | |
for p in processes: | |
p.start() | |
for p in processes: | |
p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment