Can we find A string that has exactly N leading zeros when using SHA-1 hashing?
Assume strings have the same first part like StackOverflow. I want to add characters to this string to find a string that has 5 leading zeros.
For example like below (these are not actual results):
StackOverflowfirqk ==> 000006dde7d6496f3961ac6efc9735c270f2ea23
StackOverflow66SA7 ==> 0000038cd7f75a71cb9190ad655a494ccf64eb54
In addition, I want to use all alphabet, both small and capital, and digits (and maybe other characters). The length of additional characters is not a matter but for a challenge, I want to find additional of 15 characters. Is there a way rather than brute force algorithms to do this?
What I Did So Far
Here is my code to generate and check this problem:
import itertools
import hashlib
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
for i in range(1, 21):
for seq in itertools.product(alphabet, repeat=i):
seq = "".join(seq)
input = 'StackOverflow' + seq
hex_hash = hashlib.sha1(input.encode('utf-8')).hexdigest()
binary_hash = "{0:0160b}".format(int(hex_hash, 16))
index = binary_hash.index('1')
if (index > 20):
print(input + ' ' + hex_hash + ' ==> ' + str(index))
But it is a Brute Force way and this way I have an XY Problem. Besides, if there is no way to do that rather than brute force how can we speed this up? multithreading, using big data approaches?
Comments
Post a Comment