Last active
March 20, 2020 00:10
-
-
Save packetchef/034fc8048de63172726d623ff01dc89d to your computer and use it in GitHub Desktop.
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
import re | |
import hashlib | |
import string | |
from itertools import product | |
def all_perms_with_repeat(validChars, repeatCount): | |
chars = list(validChars) | |
results = [] | |
for c in product(chars, repeat = repeatCount): | |
results.append(''.join(c)) | |
return results | |
def getMd5(checkStr): | |
#m.update(checkStr.encoding('UTF-8')) | |
m = hashlib.md5() | |
m.update(checkStr) | |
return m.hexdigest() | |
def matchRegex(r, checkStr): | |
return r.match(checkStr) | |
if __name__ == "__main__": | |
''' | |
pattern = '[abc]{3}' | |
matchStrLen = 4 | |
matchHash = 'ee594c82c8941787a621accae1f24338' | |
validChars = ['a', 'b', 'c'] | |
''' | |
pattern = '[(a|c|d)n-t\|]{8}' | |
matchStrLen = 8 | |
matchHash = 'b89e49cab317f2681be60fb3d1c0f8f8' | |
validChars = ['a', 'c', 'd', '|', '(', ')'] | |
validChars.extend([ c for c in list(string.ascii_lowercase[13:20])]) | |
print('Valid characters are: {0}'.format(validChars)) | |
prex = re.compile(pattern) | |
tries = 0 | |
with open('regex-to-hash.match', 'w') as fs: | |
for match in product(validChars, repeat = matchStrLen): | |
matchStr = ''.join(match) | |
#print('Checking {0}'.format(matchStr)) | |
#print(getMd5(matchStr)) | |
tries += 1 | |
if matchRegex(prex, matchStr) and getMd5(matchStr) == matchHash: | |
print('{0} matches!'.format(matchStr)) | |
print('Tries: {0}'.format(str(tries))) | |
fs.write('{0}:{1}\n'.format(matchStr, 'match')) | |
break | |
else: | |
fs.write('{0}:{1}\n'.format(matchStr, 'no match')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment