Untitled
unknown
python
a year ago
1.8 kB
7
Indexable
import hashlib
input_string = "cystack"
target_md5_hash = "f33e7acc20580138923e9e07f3f02536"
variants = [] # every possible of lowercase and uppercase of that character
def generate_variants(input_string, current_index=0, current_variant=""):
if current_index == len(input_string): # if the current index is equal length of input string
variants.append(current_variant) # append in the list
return # stop the recursion
# call the recursion with the input string, current position of string, current variant combine with the position of string in lower case
generate_variants(input_string, current_index + 1, current_variant + input_string[current_index].lower())
generate_variants(input_string, current_index + 1, current_variant + input_string[current_index].upper())
generate_variants(input_string) # call the function
# For example in first we call generate_variants("cystack", current_index=0, current_variant="")
# then the current_index is not equals len(cystack)=7 then run the next command which is a recursion now it will have ("cystack", 1, "" + input_string[1].lower = "c")
# then call the recursion with input_string[2].upper() = "Y"
# until it reach current_index = 7 then the array will be append
# with current_index = 1, current_variant = "c"
# with current_index = 2, current_variant = "cY"
# with current_index = 3, current_varriant = "cYs"
# and keep going
matching_variant = None
for variant in variants:
md5_hash = hashlib.md5(variant.encode()).hexdigest() # change into md5 hash
if md5_hash == target_md5_hash:
matching_variant = variant
break
if matching_variant:
print("Matching Variant:")
print(matching_variant)
else:
print("No matching variant found.")
print("All Variants:")
print(variants)Editor is loading...
Leave a Comment