-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_analyzer.py
More file actions
63 lines (49 loc) · 2.13 KB
/
batch_analyzer.py
File metadata and controls
63 lines (49 loc) · 2.13 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
import random
import string
import pandas as pd
import joblib
from main import extract_features, update_model_with_new_example, load_model, check_pwned, convert_time, _compute_override_score
def generate_random_passwords(n=30, min_len=10, max_len=20):
passwords = []
chars = string.ascii_letters + string.digits + "!@#$%^&*()_+-="
for _ in range(n):
length = random.randint(min_len, max_len)
pw = ''.join(random.choice(chars) for _ in range(length))
passwords.append(pw)
return passwords
def analyze_batch(password_list, model, auto_label=True):
for pw in password_list:
feat = extract_features(pw)
entropy = feat["entropy"]
classical_guesses = 2 ** entropy
quantum_guesses = 2 ** (entropy / 2)
classical_time = classical_guesses / 1e9
quantum_time = quantum_guesses / 1e9
ai_score = model.predict(pd.DataFrame([feat]))[0]
override_score = _compute_override_score(entropy, quantum_time)
if quantum_time < 3600 * 24: # less than 1 day
final_score = 0.2 * ai_score + 0.8 * override_score
else:
final_score = 0.5 * ai_score + 0.5 * override_score
if final_score < 0.33:
strength_label = "Weak"
elif final_score < 0.66:
strength_label = "Medium"
else:
strength_label = "Strong"
try:
breaches = check_pwned(pw)
except:
breaches = -1
print(f"Password: {pw} | AI Score: {ai_score:.3f} | Override: {override_score:.3f} | "
f"Final: {final_score:.3f} -> {strength_label} | Entropy: {entropy:.2f} | "
f"Classical Crack: {convert_time(classical_time)} | Quantum Crack: {convert_time(quantum_time)} | "
f"Breaches: {breaches}")
if auto_label:
update_model_with_new_example(pw, final_score)
print(f"\n[+] Processed {len(password_list)} passwords.")
if __name__ == "__main__":
model = load_model()
random_passwords = generate_random_passwords(50)
combined_batch = random_passwords
analyze_batch(combined_batch, model, auto_label=True)