I have this challenge I have been trying to solve. Here is the script :
import hashlib
def takingPotion(memory, key):
result = bytearray(len(memory))
for i in range(len(memory)):
result[i] = memory[i] ^ key
return bytes(result)
if __name__ == "__main__":
# Ryan's memory is all scrambled.
memory = 'd4e0b9f4fcf4f6ebe0b9f1f8effcb9fbfcfcf7b9faecebfcfdb7b9d0b9ebfcf4fcf4fbfcebb9f7f6eeb7b9daf7dce2fdaaaae9aaebc6a8f7c6e0a9ecebc6f1aaadfde4'
# The lost recipe is here, but it is a foreign language.
lostRecipe="c5a5e3dcb87d3538b366b24f459c436a"
# Enter the proper potion formula to cure Ryan.
recipe = input("Enter mental cure recipe: ")
# Mixing the potion to see if it matches the formula in his head.
mixRecipe = hashlib.md5(recipe.encode())
# Is it the right formula?
if mixRecipe.hexdigest() == lostRecipe:
# Extract the ingredients from the formula to get the proper mix.
ingredient = int((recipe[0] + recipe[1]).encode(), 16)
isCured = takingPotion(bytes.fromhex(memory), ingredient)
print (isCured.decode())
else:
print ("It didn't work!")
I think it is supposed to be much simpler than trying to crack the MD5 hash in the script. I cannot seem to understand how to resolve this in a simple way.
You need to sign in to view this answers