我正在做这本书“Violent Python”的练习,它是一个UNIX密码破解程序。这本书让人理所当然地认为,你已经将密码名称和salt作为参数传递给某个地方,这样它就可以工作,但所需的原始参数不会在任何地方声明。我应该在哪里传递/声明一个变量?如何将此代码的参数传递到工作
import crypt
def testPass(cryptPass):
salt = cryptPass[0:2]
dictFile = open('/home/cf/Downloads/CH1/dictionary.txt','r')
for word in dictFile.readlines():
word = word.strip('\n')
cryptWord = crypt.crypt(word,salt)
if (cryptWord == cryptPass):
print "[+] Found Password: "+word+"\n"
return
print "[-] Password Not Found.\n"
return
def main():
passFile = open('/home/cf/Downloads/CH1/passwords.txt')
for line in passFile.readlines():
if":" in line:
user = line.split(':')[0]
cryptPass = line.split(':')[1].strip('')
print "[*] Cracking Password For: " + user
testPass(cryptPass)
if __name__ == "__main__":
main()
您似乎是从'passwords.txt'中提取它们。 –
根据你的代码,'salt'需要'cryptPass'的前两个字符('salt = cryptPass [0:2]') – Don