intro = Text("This code is a password strength tester.
")
intro.set_position(80, 150)
intro.set_font("10pt Arial")
add(intro)
intro1 = Text("Using this code you will be able to calculate the time it would take for someone to
determine your password via the brute force method.")
intro1.set_position(10, 225)
intro1.set_font("10pt Arial")
add(intro1)
intro2 = Text("The brute force method is one in which a computer guesses every ")
intro2.set_position(5, 325)
intro2.set_font("10pt Arial")
add(intro2)
intro3 = Text("for a person to determine your password via the brute force method.")
intro3.set_position(3, 250)
intro3.set_font("10pt Arial")
add(intro3)
intro4 = Text("possible combination of characters.")
intro4.set_position(100, 350)
intro4.set_font("10pt Arial")
add(intro4)
rect = Rectangle(10, 50)
rect.set_position(get_width()/2, 375)
rect.set_color(Color.blue)
add(rect)
rect1 = Rectangle(30, 30)
rect1.set_position((get_width()/2)-10, 395)
rect1.set_color(Color.blue)
add(rect1)
rect1.set_rotation(math.radians(45))
rect2 = Rectangle(30, 30)
rect2.set_position((get_width()/2)-30, 380)
rect2.set_color(Color.white)
add(rect2)
rect3 = Rectangle(30, 30)
rect3.set_position((get_width()/2)+10, 380)
rect3.set_color(Color.white)
add(rect3)
from math import pow
# Define what characters count in each character set to determine how many
# are used
LOWERCASE = "abcdefghijklmnopqrstuvwxyz"
UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DIGITS = "0123456789"
SYMBOLS = "!@#$%^&*()-_+=<>?/|{}[]~`"
# Function to determine the character sets used in a given password by
# checking for any matching characters from the defined sets
def analyze_password(password):
has_lower = any(c in LOWERCASE for c in password)
has_upper = any(c in UPPERCASE for c in password)
has_digits = any(c in DIGITS for c in password)
has_symbols = any(c in SYMBOLS for c in password)
# adds the total number of characters in each set that is used to a total
# count in order to find the number of possible characters as the chance
# of each character is 1/(character set size)
char_set_size = 0
if has_lower:
char_set_size += len(LOWERCASE)
if has_upper:
char_set_size += len(UPPERCASE)
if has_digits:
char_set_size += len(DIGITS)
if has_symbols:
char_set_size += len(SYMBOLS)
return char_set_size
# Function to estimate the time to crack the password using brute force aka
# a computer trying every possible combination
def estimate_crack_time(password, attempts_per_second=1000000):
char_set_size = analyze_password(password)
password_length = len(password)
# Calculate the total possible combinations
total_combinations = pow(char_set_size, password_length)
# Estimate the time to crack
time_to_crack = total_combinations / attempts_per_second
return total_combinations, time_to_crack
# Prompt the user for a password to undergo the code
password = input("Enter your password: ")
# Estimate the time to crack the password
total_combinations, time_to_crack = estimate_crack_time(password)
# Format the time in a standard form
def format_time(seconds):
# break down each interval of time into seconds
intervals = (
('year', 60 * 60 * 24 * 365),
('day', 60 * 60 * 24),
('hour', 60 * 60),
('minute', 60),
('second', 1),
)
# An empty list to hold each portion of the time format for example
# days, hours, minutes and then seconds
result = []
for name, count in intervals:
# This divides the total number of seconds by the amount for each
# interval to determine if the time is high enough to fill one of
# such interval
value = seconds // count
if value:
# Subtracts the seconds of the interval from the total
seconds -= value * count
if value == 1:
name = name.rstrip('s')
# Adds the interval result to the end of the result list
result.append(f"{value} {name}")
return ', '.join(result) if result else "less than a second"
# Display the results
print("Password Length:", len(password))
print("Character Set Size:", analyze_password(password))
print("Total Combinations:", total_combinations)
print("Estimated Time to Crack:", format_time(time_to_crack))