Created
August 20, 2023 13:16
-
-
Save clickCA/2a477e89bf29a97e13820f70d12d083f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hashlib | |
| import itertools | |
| def generate_variants(word): | |
| substitutions = { | |
| 'o': '0', | |
| 'l': '1', | |
| 'i': '1' | |
| } | |
| # Generate all case variants | |
| case_variants = map(''.join, itertools.product(*zip(word.lower(), word.upper()))) | |
| final_variants = [] | |
| for variant in case_variants: | |
| temp_variants = [variant] | |
| for original, replacement in substitutions.items(): | |
| new_variants = [] | |
| for temp in temp_variants: | |
| if original in temp: | |
| new_variants.append(temp.replace(original, replacement)) | |
| temp_variants.extend(new_variants) | |
| final_variants.extend(temp_variants) | |
| return final_variants | |
| def load_dictionary(filename): | |
| with open(filename, 'r') as f: | |
| words = f.read().splitlines() | |
| return words | |
| def main(): | |
| dictionary_words = load_dictionary('./most-common.txt') | |
| target_hash = "d54cc1fe76f5186380a0939d2fc1723c44e8a5f7" | |
| for word in dictionary_words: | |
| for variant in generate_variants(word): | |
| # Check for SHA-1 match | |
| if hashlib.sha1(variant.encode()).hexdigest() == target_hash: | |
| print(f"Found original word (SHA-1): {word}") | |
| print(f"Variant: {variant}") | |
| return | |
| # Check for MD5 match | |
| elif hashlib.md5(variant.encode()).hexdigest() == target_hash: | |
| print(f"Found original word (MD5): {word}") | |
| print(f"Variant: {variant}") | |
| return | |
| print("Couldn't find a matching word from the dictionary.") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment