COLTO50 commited on
Commit
3110873
1 Parent(s): 2728e0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py CHANGED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import itertools
3
+ import string
4
+ import time
5
+ import multiprocessing
6
+ import math
7
+
8
+ def generate_passwords(chars, length, start, end):
9
+ for attempt in itertools.islice(itertools.product(chars, repeat=length), start, end):
10
+ yield ''.join(attempt)
11
+
12
+ def crack_chunk(args):
13
+ chars, length, start, end, password, chunk_id, progress_queue = args
14
+ attempts = 0
15
+ for attempt in generate_passwords(chars, length, start, end):
16
+ attempts += 1
17
+ if attempts % 1000000 == 0: # Update progress every million attempts
18
+ progress_queue.put((chunk_id, attempts))
19
+ if attempt == password:
20
+ progress_queue.put((chunk_id, attempts))
21
+ return attempts, attempt
22
+ progress_queue.put((chunk_id, attempts))
23
+ return attempts, None
24
+
25
+ def optimized_brute_force(password, progress=gr.Progress()):
26
+ start_time = time.time()
27
+ total_attempts = 0
28
+ chars = string.ascii_letters + string.digits + string.punctuation
29
+ cpu_count = multiprocessing.cpu_count()
30
+
31
+ for length in range(1, len(password) + 1):
32
+ chunk_size = math.ceil(len(chars) ** length / cpu_count)
33
+ manager = multiprocessing.Manager()
34
+ progress_queue = manager.Queue()
35
+
36
+ chunks = [
37
+ (chars, length, i * chunk_size, (i + 1) * chunk_size, password, i, progress_queue)
38
+ for i in range(cpu_count)
39
+ ]
40
+
41
+ with multiprocessing.Pool(processes=cpu_count) as pool:
42
+ results = pool.map_async(crack_chunk, chunks)
43
+
44
+ chunk_progress = [0] * cpu_count
45
+ while not results.ready():
46
+ while not progress_queue.empty():
47
+ chunk_id, attempts = progress_queue.get()
48
+ chunk_progress[chunk_id] = attempts
49
+ total_attempts = sum(chunk_progress)
50
+ progress(total_attempts, desc=f"Trying {length}-character passwords")
51
+ time.sleep(0.1)
52
+
53
+ results = results.get()
54
+
55
+ for attempts, cracked in results:
56
+ total_attempts += attempts
57
+ if cracked:
58
+ end_time = time.time()
59
+ return f"Password cracked: {cracked}\nAttempts: {total_attempts:,}\nTime taken: {round((end_time - start_time) * 1000, 2)} ms"
60
+
61
+ end_time = time.time()
62
+ return f"Password not found\nAttempts: {total_attempts:,}\nTime taken: {round((end_time - start_time) * 1000, 2)} ms"
63
+
64
+ def brute_force_interface(password):
65
+ return optimized_brute_force(password)
66
+
67
+ iface = gr.Interface(
68
+ fn=brute_force_interface,
69
+ inputs=gr.Textbox(label="Enter password to crack"),
70
+ outputs="text",
71
+ title="Brute-Force Password Cracker Simulator",
72
+ description="This simulator attempts to crack a given password using a brute-force approach. It utilizes multiple CPU cores for faster cracking. Note: This is for educational purposes only and should not be used for malicious activities.",
73
+ )
74
+
75
+ if __name__ == "__main__":
76
+ iface.launch()