简易字典生成器实现代码

 1 #!/usr/bin/python3
 2 # coding : utf-8
 3 
 4 def passwd_creation(passwd_length,characters_for_passwd,path_for_saving):
 5     ''' The first parameter is the length of password which is type <int>;
 6         The second parameter is the possiable characters for the password which is type <string>;
 7         The last parameter is the path to save passwords created;
 8     '''
 9     if(type(passwd_length)!=int or type(characters_for_passwd)!=str or type(path_for_saving)!=str):
10         print('Please be careful about the type of each parameter which is <int,str,str> in proper order!')
11         return False
12     if(passwd_length<0):
13         print('The length of password can\'t be less than zero!')
14         return False
15     try:
16         file=open(path_for_saving,'r')
17         flag=input('The file already exists!Are you wanne to override it?(y/n):')
18         if(flag!='y' and flag!='Y'):
19             print('The program has benn terminated!')
20             return False
21     except:
22         pass
23     try:
24         len_chars=len(characters_for_passwd)
25         with open(path_for_saving,'w') as passwd_file:
26             print('Length of the password: %d\nChosed characters: %s\nPath to save data: %s\nWriting data...'%(passwd_length,characters_for_passwd,path_for_saving))
27             for i in range(len_chars**passwd_length):
28                 passwd=''
29                 temp=i
30                 for j in range(passwd_length):
31                     passwd=characters_for_passwd[temp%len_chars]+passwd
32                     temp=temp//len_chars
33                 passwd_file.write(passwd+'\n')
34         print('Completed!')
35         return True
36     except:
37         print('There is something wrong happened while writing data into the file!')
38         return False
39 
40 if __name__=='__main__':
41     a=int(input('Please input the length of passwd:'))
42     b=input('Please input the possiable characters:')
43     c=input('Please input the path for saving data:')
44     passwd_creation(a,b,c)

 

转载于:https://www.cnblogs.com/apsycho/p/10478266.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值