我决定编写一个暴力破解函数来向人们展示密码的脆弱性。现在,我可以向他们展示查找密码所经历的列表,但我如何告诉他们花了多长时间? 这是代码:
#!/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"
最佳答案
首先,密码非常安全,使用暴力破解需要很多天才能找到。
但如果您愿意,可以使用以下内容:
import time
start_time = time.time()
# Your code here
stop_time = time.time()
print "Running time in sec:", stop_time - start_time
关于python -> 密码安全程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720363/