We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def find(word,lis,rlis):
if word in lis:
rlis.append(word)
return rlis
if not word:
rlis.append('W')
return rlis
if len(word) == 1:
rlis.append('W')
return rlis
head, tail = [],[]
for i in range(1,len(word)):
h,t = word[:i],word[i:]
if h in lis:
head.append(h)
tail.append(t)
# print(head, tail)
if not head:
rlis.append('W')
return rlis
for i in range(len(head)):
t = find(tail[i],lis,[])
if "W" not in t:
rlis.append(head[i])
rlis += t
return rlis
rlis.append('W')
return rlis
def passwordCracker(passwords, loginAttempt):
usepass = []
for p in passwords:
rest = [i for i in passwords if i != p]
if find(p,rest,[]) == ['W']:
usepass.append(p)
attset = {i for i in loginAttempt}
passset = set()
for i in usepass:
passset.update({j for j in i})
if len(attset - passset) > 0:
return 'WRONG PASSWORD'
# la = re.findall(r'^(\w+?)\1*$', loginAttempt)[0]
#print(la)
# count = len(loginAttempt)//len(la)
sys.setrecursionlimit(3000)
r = find(loginAttempt,usepass,[])
if r == ['W']:
return 'WRONG PASSWORD'
else:
s = ''
for i in r:
s += i + ' '
return s.rstrip(' ')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Password Cracker
You are viewing a single comment's thread. Return to all comments →
def find(word,lis,rlis): if word in lis: rlis.append(word) return rlis if not word: rlis.append('W') return rlis if len(word) == 1: rlis.append('W') return rlis head, tail = [],[] for i in range(1,len(word)): h,t = word[:i],word[i:] if h in lis: head.append(h) tail.append(t) # print(head, tail) if not head: rlis.append('W') return rlis for i in range(len(head)): t = find(tail[i],lis,[]) if "W" not in t: rlis.append(head[i]) rlis += t return rlis rlis.append('W') return rlis def passwordCracker(passwords, loginAttempt): usepass = [] for p in passwords: rest = [i for i in passwords if i != p] if find(p,rest,[]) == ['W']: usepass.append(p) attset = {i for i in loginAttempt} passset = set() for i in usepass: passset.update({j for j in i}) if len(attset - passset) > 0: return 'WRONG PASSWORD' # la = re.findall(r'^(\w+?)\1*$', loginAttempt)[0] #print(la) # count = len(loginAttempt)//len(la) sys.setrecursionlimit(3000) r = find(loginAttempt,usepass,[]) if r == ['W']: return 'WRONG PASSWORD' else: s = '' for i in r: s += i + ' ' return s.rstrip(' ')