python -> password safety program
-
12-10-2019 - |
Question
i decided to write a brute force function to show people how vulnerable a password is. right now, i can show them the list it goes through to find the password, but how do i tell them how long it took? here's the code:
#!/usr/bin/python import itertools lower_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] alllet = [] alllet = lower_a + upper_a# + num pwd = raw_input("What pwd?\t\t") try: for r in range(1, len(pwd)+1): for s in itertools.product(alllet, repeat=r): print ''.join(s) if ''.join(s) == pwd: raise NameError() except KeyboardInterrupt: print "Hey! You stopped me!" except NameError: print "DONE! CRACKED!" print "\n\nPassword is:\t" + ''.join(s) + "\n\n"
Solution
First of all passwords are quite safe and it will take many many days to find one using brute force attack.
But if you'd like you could use following:
import time
start_time = time.time()
# Your code here
stop_time = time.time()
print "Running time in sec:", stop_time - start_time
OTHER TIPS
What you need is the timeit
module. Using timeit.Timer
, you can measure the speed of your code.
Here is a good online tutorial.
Hope this helps
How long as in time?
from time import time
on top, at the start of the program do start = time()
. at the nameerror part do print time() - start
please be a bit more specific
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow