Python implements the random cipher dictionary generator example

  • 2020-04-02 13:33:43
  • OfStack

At first, I wanted to enumerate all the passwords, so the algorithm was either too deeply nested, or it was extremely memory-consuming. Then I chose an algorithm with a low probability of simple repetition. The code is as follows:


# -*- coding:utf-8 -*-
'''
 @ function:  Generate a random password dictionary 
'''
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 articles: