蟒蛇->密码安全程序

发布于 2024-10-12 15:50:59 字数 966 浏览 11 评论 0原文

我决定编写一个暴力破解函数来向人们展示密码是多么容易受到攻击。现在,我可以向他们展示查找密码所需的列表,但我如何告诉他们花了多长时间? 这是代码:

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆° 2024-10-19 15:50:59

首先,密码非常安全,使用暴力攻击需要很多天才能找到密码。

但如果您愿意,可以使用以下内容:

import time

start_time = time.time()

# Your code here

stop_time = time.time()
print "Running time in sec:", stop_time - start_time

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
山有枢 2024-10-19 15:50:59

您需要的是 timeit 模块。使用timeit.Timer,您可以测量代码的速度。

这里是很好的在线教程。

希望这有帮助

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

故事与诗 2024-10-19 15:50:59

时间上有多长?

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 do start = time(). at the nameerror part do print time() - start

please be a bit more specific

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文