-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordCracker.py
More file actions
70 lines (53 loc) · 2.25 KB
/
PasswordCracker.py
File metadata and controls
70 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time, getpass, random, string, itertools
total_time = 0
total_attempts = 0
runs = 0
gattempts = 0
print("Welcome to The Password Tester!")
print("We can test password length of 4, 8, or 12 characters.")
while True:
x = input("What length would you like to test, or type 'exit' to exit. ").lower()
if x == "exit":
print("Thank you, here are your stats for today:")
break
if not x.isdigit() or int(x) not in (4, 8, 12):
print("Please enter 4, 8, or 12.")
continue
x =int(x)
password = getpass.getpass("Enter password: \n")
while len(password) != x:
print(f"Password must be exactly {x} characters long.")
password = getpass.getpass("Enter password: \n")
print("Loading, please wait...")
symbols = "!@#$%^&*()-_+=,<>.?/:;'"
chars = string.ascii_letters + string.digits + symbols + "" #Can replace symbols for string.punctuation
attempts = 0
guess = ""
start = time.perf_counter()
timeout = 60
while guess != password:
#for combo in itertools.product(chars, repeat=x):
if time.perf_counter() - start >= timeout:
print(f"{timeout} seconds has been reached. Good job, I cant crack it!")
break
if attempts >= 10000000:
print(f"Reached {attempts} tries. Good job, I cant crack it!")
break
guess = "".join(random.choice(chars) for _ in range(x))
#guess = "".join(combo)
attempts = attempts + 1
end = time.perf_counter()
elapsed = end - start
elapsed = round(elapsed, 1)
if guess == password:
print(f"Password guessed! It's '{guess}', right?")
print(f"That wasnt so hard! It took me {elapsed} seconds and {attempts:,} tries.")
gattempts = gattempts + 1
else:
print(f"I reached {attempts:,} attempts in {elapsed} seconds. I am unable to crack. Sad face.")
total_time += elapsed
total_attempts += attempts
runs += 1
avg_time = round(total_time / runs, 2)
avg_attempts = round(total_attempts / runs)
print(f"Total attemps: {runs} \nPasswords cracked: {gattempts} \nAverage time: {avg_time} \nAverage attempts per password: {avg_attempts}")