Python generate password dictionary (Reprint)

It was a long time ago that I wanted to write this code. I always thought that the password could only remember a general idea and some elements, but I forgot what it was, so I was very tired... Then a few days ago, some students met this puzzle, they always forget the password of their school account, so they wanted to write such a script However, due to their own level is not enough, I never thought how to write it. Then I copied a script on the Internet and modified it by the way
Talk is cheap´╝îshow me the code.Here we go.

i=1
#Create password unit book in write mode
with open ("foo.txt", "w") as fo:
    text=' '
    while(text!=''):
        text=input('Please enter the%d Units(Press enter to end input):' %i)
        i=i+1
        fo.write(text+'\n')

def createWords(currentWidth,wordslist,lastresultList,totalArray):
    if 1==currentWidth:
        lastresultList=[]
        lastresultList.extend(wordslist)
        totalArray.extend(wordslist);
        return lastresultList;
    else:
        preWords= createWords( currentWidth-1, wordslist, lastresultList,totalPwd)
        lastresultList=[]
        for word in wordslist:
            for lastWord in preWords:
                newResult=word+lastWord
                totalArray.append(newResult)
                lastresultList.append(newResult)
    return lastresultList
# =============================================================================
fo=open('foo.txt','r')
array = [];
totalPwd= [];
for line in fo.readlines():
    line = line.strip("\n")
    array.append(line)
array.pop()
fo.close()
print('======================')
print('Unit data in total:%d individual' %(len(array)))


xwidth=int(input('Please enter the number of units to make up the password:')) #The number of metadata used to generate the password, and the password of 2 units can be generated. Here, it can be any integer greater than 1,
resultWorlds=createWords(xwidth,array,array,totalPwd)
print("Composed of%d Bit ciphers in total%d individual" %(xwidth,len(resultWorlds)))
with open('pw.txt','w') as f:
    for i in range(len(totalPwd)):
        f.write(totalPwd[i]+'\n')

How to use the above script: run it directly, and generate the password dictionary generated according to the specific unit according to the operation prompt

Posted on Tue, 05 May 2020 03:48:05 -0400 by globetrottingmike