生成任意字符组合的密码

import time
from itertools import product
# #列表排列组合
# k = [1, 2, 3]
# print(list(product(k, k)))
# print(list(product(k, repeat=3)))



#将元祖数据转变为字符串,返回新列表
def TupToStr(list):
    list3 = []
    n = ''
    for i in range(len(list)):
        m = list[i]
        n += m
    list3.append(n)
    return list3


#生成指定位数的密码字典
def main():
    x = int(input("你想测试几位数的密码:"))

    time_start = time.time()
    with open('txt_1', mode='w' ) as f:
        for item in product([chr(i) for i in range(33,127)], repeat=x):
            list1 = TupToStr(item)
            print(list1[0])
            f.write( list1[0]+ '\n')
    time_end = time.time()
    print(time_end - time_start)


if __name__ == "__main__":
    main()

结果:

C:\Users\ZETTAKIT\PycharmProjects\chenfan\venv\Scripts\python.exe C:/Users/ZETTAKIT/PycharmProjects/chenfan/day0418/18.3.py
你想测试几位数的密码:4
205.23994374275208

Process finished with exit code 0

……

生成的文件部分展示:

!!!!
!!!"
!!!#
!!!$
!!!%
!!!&
!!!'
!!!(
!!!)
!!!*
!!!+
!!!,
!!!-
!!!.
!!!/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值