0

Here is the program. It works great on the IDLE but, it crashes after asking if you know the password length. I can't seem to figure out want i'm missing. I would love any help.

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)
8
  • How does it crash? Can you post the exception?
    – Paulo Bu
    Jan 19, 2014 at 0:47
  • That's the thing. I can't even see what's going on.
    – Torkoal
    Jan 19, 2014 at 0:48
  • 1
    Can you provide more information? Traceback? It looks like you are using Python 3.x. Is the problem the windows disappears? If so, just add input() as the last statement so that the window stays open until you hit <enter>
    – Levon
    Jan 19, 2014 at 0:54
  • 1
    @Conner Can you clarify which version of Python you are using? Jan 19, 2014 at 0:56
  • 1
    @Levon Thanks for your generosity, but your answer works well. +1 to you. Jan 19, 2014 at 1:51

2 Answers 2

1

@275365 was right, you should use

if (raw_input("Do you have the length of the password?") == 'y'):

instead of

if (input("Do you have the length of the password?") == 'y'):

Using input() leads to a crash,

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

while changing it to raw_input() runs to completion without a crash.

3
  • The OP claims to be using Python 3.3. Unless there's a problem with multiple Python versions the OP hasn't realized (which may be the case), this isn't the answer. Jan 19, 2014 at 1:03
  • 1
    Use of the print() would indicate that i'm using 3.3 I just uninstalled 2.7 to make sure it wasn't this.
    – Torkoal
    Jan 19, 2014 at 1:05
  • @Conner What happens if you change the input() to raw_input()? I ran this w/o a crash under 3.2.3 (the only 3.x version I have access to right now).
    – Levon
    Jan 19, 2014 at 1:06
1

It seems you may be running a different version of IDLE than you are coding in. If I understand correctly, raw_input() works on your CMD but breaks in IDLE, while input() works in IDLE and breaks in CMD. You may need to download the proper version of IDLE for Python 3, or if you have it you are just accessing the one for Python 2.

Otherwise, it could be a problem with your Path variable in Windows. In System -> Advanced System Settings -> Environment Variables -> Path - which needs to be set to your Python 3.3 installation.

To me, it seems like your Path may still be stuck on the previous installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.