【问题标题】:python -> password safety programpython -> 密码安全程序
【发布时间】:2011-01-18 04:00:16
【问题描述】:

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

#!/usr/bin/python 导入迭代工具 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("什么密码?\t\t") 尝试: 对于范围内的 r (1, len(pwd)+1): 对于 itertools.product(alllet, repeat=r) 中的 s: 打印''.join(s) 如果''.join(s) == pwd: 引发名称错误() 除了键盘中断: 打印“嘿!你阻止了我!” 除了名称错误: 打印“完成!破解!” print "\n\n密码是:\t" + ''.join(s) + "\n\n"

【问题讨论】:

  • 顺便提一下,from string import printable 可能会有所帮助。
  • 只是给您的lower_aupper_anum 列表的提示:import string 并使用list(string.lowercase)list(string.uppercase)list(string.digits).
  • string.printable = string.lowercase + string.uppercase + string.digits + string.punctuation + string.whitespace

标签: python time brute-force combinations


【解决方案1】:

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

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

import time

start_time = time.time()

# Your code here

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

【讨论】:

  • 如果你投票我会接受?或者那不是我们在这里做的那种事情
  • 我不认为它是这样做的。答案正确吗?如果是,请接受。如果没有,不要。
  • 如果您喜欢这个问题或答案,您可以随时投票,并且您有权接受任何适合您的答案。来自常见问题:Reputation is completely optional. Normal use of Stack Overflow — that is, asking and answering questions — does not require any reputation whatsoever.
【解决方案2】:

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

Here 是一个很好的在线教程。

希望对你有帮助

【讨论】:

    【解决方案3】:

    时间有多长?

    from time import time 在顶部,在程序开始处执行start = time()。在名称错误部分做print time() - start

    请具体一点

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-05
      • 2017-08-16
      • 1970-01-01
      相关资源
      最近更新 更多