2014-04-30 52 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

相关问题