Talia-
If you noticed in your error log, just before the crash it showed you that you had a word with no length:
- Capitalizing:
Traceback (most recent call last):
File "/Users/Talia/Desktop/crack2-5.py", line 447, in <module>
sys.exit(main(sys.argv[1:]))
Your password list has a blank line in it. The program is trying to compare against an blank password which isn't very useful anyway, and when it tries to make the first character upper case, it dies. So please change a few things.
Code: Select all
## A little helper program to remove any weird formatting in the file
def cleanup (s, n):
s = s.strip()
if 0 == len(s):
print("Word "+str(n)+" in your word list appears to be blank!!")
return s
That's a new version of cleanup() that does the same thing but also prints a message on the screen if you read in a blank line. Since you want to know where it is in the file, it takes two arguments now instead of one. The second is the line number. It only uses it to display in the event of a blank. So since you have to pass it the line number, when you call it you call it a bit differently:
Code: Select all
## Depending on the file system, there may be extra characters before
## or after the words.
for i in range(0, number_of_words):
words[i] = cleanup(words[i],i)
Please notice that instead if calling it as "cleanup(words[ i])" we call it now as "cleanup(words[ i],i)". The second value is the line number it can use if it needs to. This happens a couple of times in the code so you have to search and find all of them to add the extra ",i".
And finally, let's make Cap() a little smarter so that if a blank word shows up it doesn't die:
Code: Select all
## A little helper program that capitalizes the first letter of a word
def Cap (s):
# If the length of the string is 0, we have nothing to uppercase
if len(s) > 0:
s = s.upper()[0]+s[1:]
return s
If the word it gets is blank, or 0 length, it doesn't do anything.
It's good that you found extra words to add to the password file. If you could do me a favor though,
please delete that section from your posting. If you remember the comment in the code about my cleaning up the 500 words so that the ones not fit for polite company would be gone, I see that you've put a bunch of them back. You probably won't need those in testing and we don't need them displayed in your post.
Make those changes and when you run the program it will run just fine but will also tell you which line of your password file has the blank line. Edit it out with your text editor - it just wastes time and slows the program down a little. At least with those modifications it shouldn't crash. The good news is that your program didn't have any errors in it - it just wasn't smart enough to handle a broken password file. A good program should be able to handle bad data. I will say that I intentionally left out any extra error checking code because it slows things down and I wanted the code to run as fast as possible. The change to cleanup() won't make any huge difference because reading in the file only happens once her method. The change to Cap() though, that adds a tiny bit of time to every call and will make a small but measurable difference in performance. If you can tell what that is, maybe this is an interesting tidbit to add to the discussion of your methods and results?
Obviously, please write back if you have any more issues or just to say things worked.
Howard