class Password(object): """docstring for Combination""" def __init__(self, chas=[chr(j) for j in range(32,127)]): super(Combination, self).__init__() self.chas = chas def straddone(self,string,index=-1): chars_len = len(self.chas) sting_len = len(string) endstr = self.chas[-1]*sting_len if string != endstr: i = self.chas.index(string[index]) if i >= chars_len-1: i = 0 arr = list(string) arr[index] = self.chas[i] string = ''.join(arr) index = index - 1 string = self.straddone(string,index) else: i = i + 1 arr = list(string) arr[index] = self.chas[i] string = ''.join(arr) return string def generate(self,string=[chr(j) for j in range(32,127)]): self.chas = string string_len = len(string) for i in range(string_len): start_string = self.chas[0]*(i+1) end_string = self.chas[-1]*(i+1) while start_string != end_string: print(start_string) start_string = self.straddone(start_string)