蟒蛇->密码安全程序
我决定编写一个暴力破解函数来向人们展示密码是多么容易受到攻击。现在,我可以向他们展示查找密码所需的列表,但我如何告诉他们花了多长时间? 这是代码:
#!/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"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,密码非常安全,使用暴力攻击需要很多天才能找到密码。
但如果您愿意,可以使用以下内容:
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:
您需要的是
timeit
模块。使用timeit.Timer
,您可以测量代码的速度。这里是很好的在线教程。
希望这有帮助
What you need is the
timeit
module. Usingtimeit.Timer
, you can measure the speed of your code.Here is a good online tutorial.
Hope this helps
时间上有多长?
from time import time
在顶部,在程序开始时执行start = time()
。在 nameerror 部分执行print time() - start
请更具体一点
How long as in time?
from time import time
on top, at the start of the program dostart = time()
. at the nameerror part doprint time() - start
please be a bit more specific