Created
August 24, 2023 09:09
-
-
Save shmalex/ec5cc583ac250330bd686e32653b8024 to your computer and use it in GitHub Desktop.
random password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
import sys | |
import argparse as ap | |
from collections import Counter as cnt | |
def rule_inrow(psw): | |
p = '' | |
for i in psw: | |
if p == i: | |
return False | |
return True | |
def rule_total(psw, maxx=5): | |
if max(cnt(psw).values()) > maxx: | |
return False | |
return True | |
def check_pass(psw, checklist): | |
for cl in checklist: | |
if cl(psw) == False: | |
return False | |
return True | |
def generate_char(): | |
return chr(np.random.randint(35, 126)) | |
def generate_pass(length=75): | |
ret = [generate_char()] | |
while len(ret)< length: | |
new_char = generate_char() | |
if check_pass(''.join(ret + [new_char]), [rule_inrow, rule_total]): | |
ret.append(new_char) | |
return ret | |
if __name__ == "__main__": | |
print(''.join(generate_pass()), flush=True) | |
sys.stderr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment