【Python】指定字符密码生成

【Python】指定字符密码生成,第1张

就是一个回溯算法,写着玩玩

keyi = []
data = []

def whatWord():
    while True:
        word = input("请输入可疑字符,输入shier结束")
        if word == "shier":
            break
        keyi.append(word)

def backtracking(keyi, start, data, count, cout_keyi):
    if (start > cout_keyi-1 and not data) or start > cout_keyi:
        return
    if len(data) == count:
        with open('pass.txt', mode="a") as f:
            f.write(''.join(data))
            f.write('\n')
        return
    for i in range(start, cout_keyi):
        if keyi[i] not in data:
            data.append(keyi[i])
            backtracking(keyi, start, data, count, cout_keyi)
            del(data[-1])

def passMaker(keyi):
    count_keyi = len(keyi)
    for i in range(1, count_keyi+1):
        backtracking(keyi, 0, data, i, count_keyi)
whatWord()
passMaker(keyi)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/580563.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存