i'm beginner programmer , thought cool create program loop through "all" possible passwords. on scale of 1-10, how efficient rate following "hacking program?" there way make following code more efficient? algorithms or tricks may know of?
i've considered moving 'e' , more common letters beginning of character array since letters used more commonly.
import sys password = raw_input("enter password: ") characters = [] lower = ["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","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"] number = ["1","2","3","4","5","6","7","8","9","0"] symbol = ["!","@","#","$","%","^","&","*","(",")","_","+","-","="] #creates array keyboard characters in range(len(lower)): characters.append(lower[i]) in range(len(upper)): characters.append(upper[i]) in range(len(number)): characters.append(number[i]) in range(len(symbol)): characters.append(symbol[i]) found = false #for 1 character passwords in range(len(characters)): if (characters[a] == password): print (characters[a]) found = true if (found): sys.exit() #for 2 character passwords in range(len(characters)): b in range(len(characters)): if (characters[a] + characters[b] == password): print (characters[a] + characters[b]) found = true if (found): sys.exit() in range(len(characters)): b in range(len(characters)): c in range(len(characters)): if (characters[a] + characters[b] + characters[c] == password): print (characters[a] + characters[b] + characters[c]) found = true if (found): sys.exit() in range(len(characters)): b in range(len(characters)): c in range(len(characters)): d in range(len(characters)): if (characters[a] + characters[b] + characters[c] + characters[d] == password): print (characters[a] + characters[b] + characters[c] + characters[d]) found = true if (found): sys.exit() in range(len(characters)): b in range(len(characters)): c in range(len(characters)): d in range(len(characters)): e in range(len(characters)): if (characters[a] + characters[b] + characters[c] + characters[d] + characters[e] == password): print (characters[a] + characters[b] + characters[c] + characters[d] + characters[e]) found = true if (found): sys.exit()
first of all, didn't have type symbols
>>> import string >>> string.uppercase 'abcdefghijklmnopqrstuvwxyz' >>> string.lowercase 'abcdefghijklmnopqrstuvwxyz' >>> string.digits '0123456789' >>>
so can do:
lower = string.lowercase
and forth
this can go away:
#creates array keyboard characters in range(len(lower)): characters.append(lower[i]) in range(len(upper)): characters.append(upper[i]) in range(len(number)): characters.append(number[i]) in range(len(symbol)): characters.append(symbol[i])
and replaced with:
characters = "".join(upper, lower, number, symbol)
this can simplified:
#for 1 character passwords in range(len(characters)): if (characters[a] == password): print (characters[a]) found = true if (found): sys.exit()
to:
for in characters: print sys.exit()
the multi-character checks need loop, try writing loops showed in single character code above
Comments
Post a Comment