md5 analyzer finalized

This commit is contained in:
Christoph J. Scherr 2023-04-24 19:10:11 +02:00
parent 5e38f6cdf5
commit b6d22ed3b8
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 11 additions and 8 deletions

View File

@ -27,6 +27,7 @@ def main():
if args.iterate: if args.iterate:
if not args.input: if not args.input:
args.input = "" args.input = ""
if not args.quiet:
print('='*80) print('='*80)
hashlist = [] hashlist = []
searchbytes = "0000" searchbytes = "0000"
@ -34,21 +35,23 @@ def main():
# args.max should be included, so +x for the counter # args.max should be included, so +x for the counter
input = (args.input + str(i)) input = (args.input + str(i))
hash = hashlib.md5(input.encode()) hash = hashlib.md5(input.encode())
found = False
# print only every 1000 lines for performance # print only every 1000 lines for performance
if not args.quiet and i % 1000 == 0 or args.print_all:
print("inp %s\t\t| out %s" % (input, hash.hexdigest()))
if hash.hexdigest()[0:4] == searchbytes: if hash.hexdigest()[0:4] == searchbytes:
found = True
hashlist.append((input, hash.hexdigest())) hashlist.append((input, hash.hexdigest()))
if not args.quiet: if not args.quiet and (found or i % 1000 == 0 or args.print_all):
print("inp %s\t\t| out %s" % (input, hash.hexdigest()))
if found:
print("^" * 80) print("^" * 80)
print('='*80) print('='*80)
for (index, hash) in hashlist: for (index, hash) in hashlist:
print("inp %s\t\t| has %s" % (index, hash)) print("inp %s\t\t| has %s" % (index, hash))
print('='*80) print('='*80)
size_searchbytes = 2**16 size_searchbytes = 16**4
expected = 16**32 / size_searchbytes # 32 hex value chars in an md5 hash expected = args.max / size_searchbytes # 32 hex value chars in an md5 hash
print("found %d items (%f%%)" % (len(hashlist), len(hashlist) / size_searchbytes)) print("found %d items (%f%%) from %d" % (len(hashlist), len(hashlist) / size_searchbytes, args.max))
print("Expected %d (%f%%) from %d" % (expected, expected / size_searchbytes, args.max)) print("Expected %f (%f%%) from %d" % (expected, expected / size_searchbytes, args.max))
exit() exit()
if args.input: if args.input: