Created
March 24, 2019 23:09
-
-
Save Sparrow1029/99236d6bc263b113c32f7cce75e10e69 to your computer and use it in GitHub Desktop.
Increment a number and hash it using chosen algorithm to find partial collisions
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
#!/usr/bin/env python3 | |
import hashlib | |
import whirlpool | |
import sys | |
algo = sys.argv[1] | |
target = sys.argv[2] | |
def gen_hash(algo, target): | |
candidate = 0 | |
if algo == 'md5': | |
hash_algo = lambda x: hashlib.md5(x.encode('ascii')).hexdigest() | |
elif algo == 'sha1': | |
hash_algo = lambda x: hashlib.sha1(x.encode('ascii')).hexdigest() | |
elif algo == 'whirlpool': | |
hash_algo = lambda x: whirlpool.new(x.encode('ascii')).hexdigest() | |
while True: | |
plaintext = str(candidate) | |
hs = hash_algo(plaintext) | |
if hs[:len(target)] == target: | |
print(f"plaintext: {plaintext}, {algo} hash: {hs}") | |
break | |
candidate += 1 | |
gen_hash(algo, target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment