2014-04-30 51 views
-2

嗨當​​我選擇選項我alaways得到這個錯誤NameError:名字 'SHA1' 沒有定義

回溯(最後最近一次調用): 文件 「ran.py」 26行,在 SHA1() NameError:名字「SHA1」沒有定義 但我不知道是什麼問題,是我打過電話之前,把功能,但總是同樣的事情

def main(): 
print '1 - SHA1 Decrypter' 
print '2 - MD5 Decrypter' 
select = input("select option :") 

if select==1: 
    sha1() 
elif select==2: 
    md5() 


def sha1(): 
    try: 
    sha1 = raw_input("\t\n\nMD5 Hash:") 
    dictionary = open("pwds.txt","r") 
    except(IOError): 
    print "pwds.txt not found!" 
for passwd in dictionary.read().split('\n'): 
    if hashlib.sha1(passwd).hexdigest() == sha1: 

     print("\n\t[OK]"+sha1+" : "+passwd+"\n") 
     raw_input("Decrytion Success; Press Enter To Exit") 

else: 
     print "\n\tFailed; Password not found in dictionary" 
     main() 

def md5(): 
    try: 
    md5 = raw_input("\t\n\nMD5 Hash:") 
    dictionary = open("pwds.txt","r") 
    except(IOError): 
    print "pwds.txt not found!" 
for passwd in dictionary.read().split('\n'): 
    if hashlib.md5(passwd).hexdigest() == md5: 

     print("\n\t[OK]"+md5+" : "+passwd+"\n") 
     raw_input("Decrytion Success; Press Enter To Exit") 

else: 
     print "\n\tFailed; Password not found in dictionary" 
     main() 
main() 
+3

請修復您的縮進。 – senshin

+1

您需要在調用之前定義該功能。此外,你似乎正在使用一個名爲'''sha1'''的變量。不要這樣做! – wnnmaw

回答

0

有代碼的多個錯誤

import hashlib 

def main(): 
    print '1 - SHA1 Decrypter' 
    print '2 - MD5 Decrypter' 
    select = input("select option :") 

    if select==1: 
     sha1() 
    elif select==2: 
     md5() 


def sha1(): 
    try: 
     sha1 = raw_input("\t\n\nMD5 Hash:") 
     dictionary = open("pwds.txt","r") 

     for passwd in dictionary.read().split('\n'): 
      if hashlib.sha1(passwd).hexdigest() == sha1: 

       print("\n\t[OK]"+sha1+" : "+passwd+"\n") 
       raw_input("Decrytion Success; Press Enter To Exit") 

     else: 
      print "\n\tFailed; Password not found in dictionary" 
      main() 
    except(IOError): 
     print "pwds.txt not found!" 

def md5(): 
    try: 
     md5 = raw_input("\t\n\nMD5 Hash:") 
     dictionary = open("pwds.txt","r") 
     for passwd in dictionary.read().split('\n'): 
      if hashlib.md5(passwd).hexdigest() == md5: 
       print("\n\t[OK]"+md5+" : "+passwd+"\n") 
       raw_input("Decrytion Success; Press Enter To Exit") 

     else: 
      print "\n\tFailed; Password not found in dictionary" 
      main() 
    except(IOError): 
     print "pwds.txt not found!" 
main() 
  1. python中的縮進非常重要,因爲它決定了塊的範圍。我不知道你是否有錯誤的縮進或發佈時發生錯誤。
  2. 您必須導入hashlib
  3. 您必須聲明並使用try塊內的字典。
+0

Hashlib也會導入縮進,這是我發佈時的錯誤 – user3578719

相關問題