Home > Backend Development > Python Tutorial > python实现随机密码字典生成器示例

python实现随机密码字典生成器示例

WBOY
Release: 2016-06-16 08:44:35
Original
2110 people have browsed it

本来想穷举所有密码,算法要么就嵌套太深,要么就特别耗内存(会溢出).后来选了一个简单重复概率很低的算法.代码如下:

复制代码 代码如下:

# -*- 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)
 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template