import hashlib
from random import randint
ALGS = ('sha3_512', 'sha384', 'md5', 'shake_128', 'sha256', 'sha3_256', 'sha3_224', 'sha512', 'blake2s', 'sha3_384', 'sha224', 'shake_256', 'blake2b', 'sha1')
first = 1
last = 999999
def prepare_target(target):
if not isinstance(target, bytearray):
if not isinstance(target, str):
target = str(target)
target = target.encode()
return target
def calc_hash(alg, target):
target = prepare_target(target)
if alg in ALGS:
command = f'hashlib.{alg}({target})'
try:
return eval(command).hexdigest()
except TypeError:
pass
def create_test_target(target_hash):
if target_hash is not None:
return '1'*len(target_hash)
def detect_hash_alg(target_hash):
result_algs = []
for alg in ALGS:
test_target = create_test_target(target_hash)
my_hash = calc_hash(alg, test_target)
if my_hash is not None:
lenght = len(my_hash)
if lenght == len(target_hash):
result_algs.append(alg)
return result_algs
def find_target(target_hash):
stop = False
algs = detect_hash_alg(target_hash)
print(f'подходящие алгоритмы: {algs}')
for i in range(first, last+1):
for alg in algs:
first_hash = calc_hash(alg, i)
if first_hash == target_hash:
print(f'founded\t{i} {alg}')
stop = True
break
if stop:
break
if not stop:
print(f'for {target_hash} not found')
if __name__ == '__main__':
target_hash = '127b1f0d6253fdfe78d806497217f2454a30e124d1f655b6c2a8c68f6dc7a7061993557b50252f253220a3a059142290cd0c2c467c0ee5bfbbd6a8a538c5d040'
test = randint(first, last+1)
alg = 'sha256'
test_hash = calc_hash(alg, test)
print(test_hash)
print(f'target \t{test} {alg}')
print('тестовый поиск:')
find_target(test_hash)
print('боевой поиск:')
find_target(target_hash)