python实现随机密码字典生成器示例
本来想穷举所有密码,算法要么就嵌套太深,要么就特别耗内存(会溢出).后来选了一个简单重复概率很低的算法.代码如下:
代码如下:
# -*- coding:utf-8 -*- ''' @ function: 生成随机密码字典 ''' import random class Dictor(): CSet=' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_-+=/*<>:;\'"[]{}|' def __init__(self,minlen,maxlen): if maxlen>minlen: self.__minlen=minlen self.__maxlen=maxlen else: self.__minlen=maxlen self.__maxlen=minlen def __iter__(self): return self def __next__(self): ret='' for i in range(0,random.randrange(self.__minlen,self.__maxlen+1)): ret+=random.choice(Dictor.CSet) return ret if __name__=='__main__': for str in Dictor(6,16): print(str)
相关推荐
Linux学堂 2019-10-14
YichengGu 2019-09-08
0bytes 2019-09-02
WelcomeToMyBlog 2008-10-07
ywybj 2019-03-07
wgPython 2019-02-27
安在信息安全新媒体 2017-11-28
HTML5 CSS3 2016-12-26
黑客基地 2016-10-19