I want to find an alphabetical string that is anywhere between 1-4 characters long.
I start off by iterating through the list of 52 letters:
letters = string.ascii_letters
I then need to iterate through the same list for the next 3 characters of the string until I find the string I am looking for.
If each _ represents the list of 52 letters, I need to basically do this, while checking for a match at each iteration:
_
_ _
_ _ _
_ _ _ _
How would I best structure a series of loops to do this?
If the premise of the question seems confusing, this is for a problem set on brute force cracking. I have simply extracted the part of the question that I am struggling with.
Edit: This is where I've got to so far.
#we know the salt is the 2-digit '50'
#we know the key is limited to 4 alphabetical letters
#cycle through all possibilities of the key till we match the hash
letters = string.ascii_letters
lcounter = 0
i = 0
j = 0
k = 0
l = 0
tryhash = "a"
word = [letters[i]]
while(tryhash != hash):
for c in letters:
word = [letters[i]] #this does not work as the additional letters need to be appended to word after the first lcounter loop
tryword = ''.join(word)
tryhash = crypt.crypt(tryword, "50")
if (tryhash == hash):
print(word)
break
i += 1
if (lcounter > 0) and (i == 52):
i = 0
if (lcounter == 1) and (j == 0):
word.insert(lcounter, letters[j])
j += 1
if (lcounter > 1) and (k == 52):
j = 0
if (lcounter == 2) and (k == 0):
word.insert(lcounter, letters[k])
k += 1
if (lcounter > 2) and (k == 52):
k = 0
if (lcounter == 3) and (l == 0):
word.insert(lcounter, letters[l])
l += 1
lcounter += 1