In [43]:
myinput = 'uqwqemis'
In [32]:
import hashlib
def md5hash(myinput):
hasher = hashlib.md5()
hasher.update(myinput.encode('utf-8'))
return hasher.hexdigest()
def is_valid(myhash):
lower_bound = int('0x' + '00000' + 'f'*27, 16)
if int(myhash, 16) > lower_bound:
return False
else:
return True
def password(myinput):
i = 0
j = 0
pswd = ''
while i < len(myinput):
myhash = md5hash(myinput + str(j))
if is_valid(myhash):
pswd += myhash[5]
i += 1
j += 1
return pswd
In [33]:
password(myinput)
Out[33]:
In [45]:
def complex_password(myinput):
i = 0
j = 0
pswd = [None] * len(myinput)
while i < len(myinput):
myhash = md5hash(myinput + str(j))
if is_valid(myhash):
pos = int(myhash[5], 16)
if (pos in range(len(myinput))) and (pswd[pos] is None):
pswd[pos] = myhash[6]
i += 1
j += 1
return ''.join(pswd)
In [46]:
complex_password(myinput)
Out[46]:
In [ ]: