Skip to content

Instantly share code, notes, and snippets.

@klement97
Last active April 15, 2019 12:05
Show Gist options
  • Save klement97/1ab80a78459ed1543607e67866c17a3b to your computer and use it in GitHub Desktop.
Save klement97/1ab80a78459ed1543607e67866c17a3b to your computer and use it in GitHub Desktop.
This code generates a random password with selecting randomly from all charachters and then tries to break this password
import random
def get_char():
return random.choice(characters)
def print_password(password):
print("auto-generated password is:")
print(password)
def set_password(strength):
password = ""
if strength == "1":
for i in range(6):
password += get_char()
return password
elif strength == "2":
for i in range(10):
password += get_char()
return password
elif strength == "3":
for i in range(14):
password += get_char()
return password
elif strength == "4":
for i in range(20):
password += get_char()
return password
characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '&', '*', '(', ')']
strength = input("Enter strength: 1 for weak - 2 for medium - 3 for strong - 4 for extra strong: ")
password = set_password(strength)
print_password(password)
print("now i will try to break your password")
n = len(characters)
m = len(password)
found = ""
j=0
i=0
while i < n:
deneme = characters[i]
while j < m:
if deneme == password[j]:
found += deneme
j += 1
i = 0
print(found)
break
else:
i += 1
break
if found == password:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment