In this assignment, we have to iteratively run data through a SHA256 algorithm replacing a number (X) with the final goal of finding a SHA256 Hash that has 11 zeroes in the beginning.
So here is the code I came up with:
for x in range(8388608000000):
hash = hashlib.sha256((str(bn) + str(x) + str(d)).encode('utf-8')).hexdigest()
if hash.find("00000000000", 0, 11) > -1:
print(x)
print(hash)
This works, but it's too slow in python. Apparently hashlib is compiled but jumping in and out because of the for loop makes things slow. I allready made multiprocessing work but that just doesn't cut it. Is there a way of getting rid of the for loop and using numpy instead somehow in this case?
- Approach:
- Create large array with numpy.arange
- using numpy.nditer instead of x within hashlib function
- writing calculated hashes into another array
- checking if hashes exist for required conditions, printing these
- iterating the process with a for loop
- Approach: I saw this solution for a similar problem although I do not fully understand what it means. Could it be useful in my case?