Skip to content

Instantly share code, notes, and snippets.

@Sparrow1029
Created March 24, 2019 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sparrow1029/99236d6bc263b113c32f7cce75e10e69 to your computer and use it in GitHub Desktop.
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
#!/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