本来想穷举所有密码,算法要么就嵌套太深,要么就特别耗内存(会溢出).后来选了一个简单重复概率很低的算法.代码如下:
复制代码 代码如下:
'''
@ 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)
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8