这是程序。它在IDLE上工作得很好但是在询问你是否知道密码长度后崩溃了。我似乎无法弄清楚我是否想要失踪。我很乐意帮忙。
import itertools
import string
import sys, os, cmd
from datetime import datetime
FMT = '%Y-%m-%d %H:%M:%S'
passwordstried = 0
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0,]
#symbols = [
lowercaseletters = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","g","h","j","k","l","z","x","c","v","b","n","m"]
uppercaseletters = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","G","H","J","K","L","Z","X","C","V","B","N","M"]
stuff = lowercaseletters + uppercaseletters + numbers
if (input("Do you have the length of the password?") == 'y'):
lengthstartingvalue = int(input("Password length: "))
else:
lengthstartingvalue = 0
starttime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(starttime)
starttime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for L in range(lengthstartingvalue, len(stuff)+1):
for subset in itertools.combinations_with_replacement(stuff, L):
print(subset)
passwordstried = passwordstried + 1
if (L>lengthstartingvalue-1):
break
endtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
elapsed = datetime.strptime(endtime, FMT) - datetime.strptime(starttime, FMT)
print ('Time elapsed:',elapsed)
print ('Passwords tried:',passwordstried)
答案 0 :(得分:1)
@ 275365是对的,你应该使用
if (raw_input("Do you have the length of the password?") == 'y'):
而不是
if (input("Do you have the length of the password?") == 'y'):
使用input()
会导致崩溃,
In [11]: run tt.py
Do you have the length of the password?y
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
C:\Program Files (x86)\ipython-0.12.1\IPython\utils\py3compat.py in execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):
D:\Users\sp\Desktop\tt.py in <module>()
16 stuff = lowercaseletters + uppercaseletters + numbers
17
---> 18 if (input("Do you have the length of the password?") == 'y'):
19 lengthstartingvalue = int(input("Password length: "))
20 else:
D:\Users\sp\Desktop\<string> in <module>()
NameError: name 'y' is not defined
将其更改为raw_input()
时会运行完成而不会崩溃。
答案 1 :(得分:1)
似乎你可能正在运行一个不同于IDLE的IDLE版本。如果我理解正确,raw_input()可以在你的CMD上运行但是在IDLE中断,而input()在IDLE中工作并在CMD中断。您可能需要为Python 3下载适当版本的IDLE,或者如果您拥有它,则只需访问Python 2的版本。
否则,Windows中的Path变量可能会出现问题。在系统 - &gt;高级系统设置 - &gt;环境变量 - &gt;路径 - 需要设置为Python 3.3安装。
对我来说,似乎你的Path可能仍然停留在以前的安装上。