python -> 密码安全程序

标签 python time brute-force combinations

我决定编写一个暴力破解函数来向人们展示密码的脆弱性。现在,我可以向他们展示查找密码所经历的列表,但我如何告诉他们花了多长时间? 这是代码:


#!/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/

相关文章:

python - 当两点之间存在视线时,如何计算父节点和邻居节点之间的距离?

python - 从 __init__.py 重新导出模块的正确方法

php - 测量 PHP 中代码段之间耗时

php - 限制登录试图防止 BFA

python - 将 XYZ 文件中的不规则 3d 数据插值到规则网格

python - django 中@login_required 和@method_decorator(login_required) 有什么区别

python - 如何将 python time.struct_time 对象转换为 ISO 字符串?

ios - 极长的 Swift 编译时间

c - 如何迭代生成字母和数字的所有可能组合以与可变长度字符串匹配?

algorithm - 调用两半floor(x/2)和ceil(x/2)的递归函数的时间复杂度