-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackxercise1.py
More file actions
40 lines (29 loc) · 970 Bytes
/
Copy pathhackxercise1.py
File metadata and controls
40 lines (29 loc) · 970 Bytes
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
import time
real_password = '1357'
def check_password(password):
if len(password) != len(real_password):
return False
for x, y in zip(password, real_password):
time.sleep(0.1) # Simulates the wait time of the safe's mechanism
if int(x) != int(y):
return False
return True
def crack_password():
pass_range = range(4)
guess = list(str(x) for x in pass_range)
for idx in pass_range:
for digit in range(10):
guess[idx] = str(digit)
guess_pass = ''.join(guess)
start_time = time.perf_counter()
hacked = check_password(guess_pass)
elapsed_time = (round(time.perf_counter() - start_time, 1))
if hacked:
return guess_pass
if elapsed_time == (idx + 2) / 10:
break
t = time.perf_counter()
pwd = crack_password()
print(pwd)
elapsed = (round(time.perf_counter() - t, 1))
print(elapsed)