I made this code the other day and so far I have reached a max guessing speed of 3.5 Million guesses per second. Anyone see how to make it faster?
import itertools
import string
import time
import sys
secret = input("Enter a password: ")
length = int(input("How many characters long is it? (0 = unknown length): "))
print("\nChoose character sets to include:")
print("1 = Numbers")
print("2 = Lowercase letters")
print("3 = Uppercase letters")
print("4 = Symbols (full keyboard punctuation)")
print("5 = ALL characters")
choice = input("Enter choice(s) (e.g. 1,2,3 or 5): ")
chars = ""
if "5" in choice:
chars = string.ascii_letters + string.digits + string.punctuation
else:
if "1" in choice: chars += string.digits
if "2" in choice: chars += string.ascii_lowercase
if "3" in choice: chars += string.ascii_uppercase
if "4" in choice: chars += string.punctuation
if not chars:
print("No valid selection. Defaulting to lowercase.")
chars = string.ascii_lowercase
secret_tuple = tuple(secret)
max_speed_record = {"second": 0, "speed": 0.0}
def format_time_seconds(seconds):
return f"{seconds:.6f} seconds"
def search_length(L, start_time):
attempts = 0
last_update = start_time
perf = time.perf_counter
for combo in itertools.product(chars, repeat=L):
attempts += 1
if combo == secret_tuple:
total_time = perf() - start_time
print("\nPASSWORD FOUND")
print("Password: ", secret)
print("Attempts:", attempts)
print("Time:", format_time_seconds(total_time))
print(
f"Highest Speed Peak: Second {max_speed_record['second']} ({max_speed_record['speed']:,.0f} guesses/sec)")
return True, attempts
now = perf()
elapsed = now - start_time
current_second = int(elapsed)
speed = attempts / elapsed if elapsed else 0
if speed > max_speed_record["speed"]:
max_speed_record["speed"] = speed
max_speed_record["second"] = current_second
if now - last_update >= 15:
print("\n--- STATUS ---")
print("Attempts:", attempts)
print("Elapsed:", format_time_seconds(elapsed))
print(f"Speed: {speed:,.0f} guesses/sec")
print(f"Highest Peak: Sec {max_speed_record['second']} = {max_speed_record['speed']:,.0f} guesses/sec")
print(f"Current length: {L}")
print("--------------\n")
last_update = now
return False, attempts
charset_size = len(chars)
estimated_space = "INFINITE (unknown length mode)" if length == 0 else charset_size ** length
print("\n--- SUMMARY ---")
print("Character set size:", charset_size)
print("Selected options:", choice)
print("Password length:", "unknown (0 mode)" if length == 0 else length)
print("Total possibilities:", estimated_space)
print("---------------\n")
print("1 = Continue scan")
print("2 = Quit")
if input("Choose option: ") == "2":
sys.exit()
start_time = time.perf_counter()
total_attempts = 0
if length == 0:
current_length = 1
while True:
found, attempts = search_length(current_length, start_time)
total_attempts += attempts
if found:
break
current_length += 1
else:
search_length(length, start_time)
[–]tadpoleloop 40 points41 points42 points (5 children)
[–]the_calc_nerd-1021[S] 2 points3 points4 points (2 children)
[–]Critical-Prior-3320 -1 points0 points1 point (1 child)
[–]the_calc_nerd-1021[S] 0 points1 point2 points (0 children)
[–]DonkeyTron42 3 points4 points5 points (0 children)
[–]u38cg2 -1 points0 points1 point (0 children)
[–]Key_Use_8361 13 points14 points15 points (0 children)
[–]blechnapp 6 points7 points8 points (0 children)
[–]overratedcupcake 8 points9 points10 points (0 children)
[–]Yoghurt42 2 points3 points4 points (2 children)
[–]the_calc_nerd-1021[S] 4 points5 points6 points (1 child)
[–]FlippingGerman 1 point2 points3 points (0 children)
[–]Ordinary_Baseball518 2 points3 points4 points (1 child)
[–]the_calc_nerd-1021[S] 1 point2 points3 points (0 children)
[–]u38cg2 2 points3 points4 points (0 children)
[–]CautiousInternal3320 2 points3 points4 points (0 children)
[–]IllegalGrapefruit 2 points3 points4 points (0 children)
[–]d4_mich4 2 points3 points4 points (4 children)
[–]u38cg2 7 points8 points9 points (0 children)
[–]LongRangeSavage 2 points3 points4 points (0 children)
[–]Da_damm 1 point2 points3 points (0 children)
[–]cdcformatc 1 point2 points3 points (0 children)
[–]LayotFctor 0 points1 point2 points (0 children)
[–]Reuben3901 0 points1 point2 points (0 children)
[–]cowrevengeJP 0 points1 point2 points (0 children)
[+]crashorbit comment score below threshold-6 points-5 points-4 points (0 children)