Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- from time import time
- import string
- upper = string.ascii_uppercase
- lower = string.ascii_lowercase
- digits = string.digits
- punctuation = string.punctuation
- groups = [upper, lower, digits, punctuation]
- password = input("Enter a password ")
- print_gen_pass = input("Pring the generated passwords? y/n ")
- def pass_contains(group):
- """return a list of the characters used in password
- then appended to 'res' variable"""
- for ch in password:
- if ch in group:
- return True
- return False
- def gen_password(length):
- """generate random password"""
- res = [pass_contains(g) for g in groups]
- new_group = []
- g_pass = ""
- for i, group in zip(res, groups):
- if i:
- new_group.append(group)
- while len(g_pass) < length:
- g_pass += choice(choice(new_group))
- return g_pass
- def timing(fn):
- """used to calculate time"""
- def wrapper():
- start_time = time()
- a = fn()
- end_time = time()
- print(f"Time elapsed {end_time - start_time}")
- return wrapper
- @timing
- def run():
- """run the code"""
- r = True
- while r:
- rand_pass = gen_password(len(password))
- r = rand_pass != password
- print("Password cracked!")
- print(run())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement