Python for 循環的黑色料理

Linux的口令破解spa

 

Python for循環能夠遍歷任何序列的項目,如一個列表或者一個字符串。code

語法:blog

for循環的語法格式以下:ip

for iterating_var in sequence:
    statements(s)

 

 1 import crypt
 2 
 3 def testPass(cryptPass):
 4     slat = cryptPass[0:2]
 5 
 6 dictFile = open('dictionary.txt','r')
 7 for word in dictFile.readlines():
 8     word = word.strip('\n')
 9     cryptWord = crypt.crypt(word,salt)
10     if (cryptWord == cryptPass):
11         print "[+] Found Password: "+word+"\n"
12         return
13 
14     print"[-] Password Not Found. \n"
15     return
16 
17 def main():
18     passFile = open('passwords.txt')
19     for line in passFile.readlines():
20         if ":" in line:
21           user = line.split(':')[0]
22           cryptPass = line.split(':')[1].split(' ')
23           print "[*] Cracking Password for: "+user
24           testPass(cryptPass)
25 
26 if __name__ == "__main__":
27     main()
相關文章
相關標籤/搜索