import gradio as gr import itertools import string import time import multiprocessing import math def generate_passwords(chars, length, start, end): for attempt in itertools.islice(itertools.product(chars, repeat=length), start, end): yield ''.join(attempt) def crack_chunk(args): chars, length, start, end, password, chunk_id, progress_queue = args attempts = 0 for attempt in generate_passwords(chars, length, start, end): attempts += 1 if attempts % 1000000 == 0: # Update progress every million attempts progress_queue.put((chunk_id, attempts)) if attempt == password: progress_queue.put((chunk_id, attempts)) return attempts, attempt progress_queue.put((chunk_id, attempts)) return attempts, None def optimized_brute_force(password, progress=gr.Progress()): start_time = time.time() total_attempts = 0 chars = string.ascii_letters + string.digits + string.punctuation cpu_count = multiprocessing.cpu_count() for length in range(1, len(password) + 1): chunk_size = math.ceil(len(chars) ** length / cpu_count) manager = multiprocessing.Manager() progress_queue = manager.Queue() chunks = [ (chars, length, i * chunk_size, (i + 1) * chunk_size, password, i, progress_queue) for i in range(cpu_count) ] with multiprocessing.Pool(processes=cpu_count) as pool: results = pool.map_async(crack_chunk, chunks) chunk_progress = [0] * cpu_count while not results.ready(): while not progress_queue.empty(): chunk_id, attempts = progress_queue.get() chunk_progress[chunk_id] = attempts total_attempts = sum(chunk_progress) progress(total_attempts, desc=f"Trying {length}-character passwords") time.sleep(0.1) results = results.get() for attempts, cracked in results: total_attempts += attempts if cracked: end_time = time.time() return f"Password cracked: {cracked}\nAttempts: {total_attempts:,}\nTime taken: {round((end_time - start_time) * 1000, 2)} ms" end_time = time.time() return f"Password not found\nAttempts: {total_attempts:,}\nTime taken: {round((end_time - start_time) * 1000, 2)} ms" def brute_force_interface(password): return optimized_brute_force(password) iface = gr.Interface( fn=brute_force_interface, inputs=gr.Textbox(label="Enter password to crack"), outputs="text", title="Brute-Force Password Cracker Simulator", 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.", ) if __name__ == "__main__": iface.launch()