无法让crypt正常工作

Rus*_*ams 1 python crypt

我只是在弄乱我是否可以使用'crypt'模块而且我似乎遇到了一个我无法解决的问题.运行之后的输出是这样的:

Password Not Found. secret HXXxJi0n6Huro HXXxJi0n6Huro
Run Code Online (Sandbox Code Playgroud)

这意味着cryptWord和cryptPass是相同的,所以为什么程序不执行(if cryptWord == cryptPass:),和print 'Found Password:

我根本没有得到它.

dictionary.txt文件中只有多个单词secret,都在不同的行上.而且evil.txt文件有这一行:

test_user:HXXxJi0n6Huro
Run Code Online (Sandbox Code Playgroud)

据我所知,一切正常吗?但有些东西正在从正常工作中恢复过来,我无法弄明白.任何帮助,将不胜感激.

import crypt

def testPass(cryptPass):

        salt = cryptPass[0:2]
        dictFile = open('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. " +word,  cryptWord,  cryptPass+  "\n"
        return


def main():

    passFile= open('evil.txt')
    for line in passFile.readlines():
        if ":" in line:
            user = line.split(':')[0]
            cryptPass = line.split(':')[1]
            print "[*] Cracking Password For: "+user
            testPass(cryptPass)
if __name__ == '__main__':

        main()
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 6

您的crypPass价值仍附有换行符.剥离它:

user, cryptPass = line.split(':')
cryptPass = cryptPass.strip()
Run Code Online (Sandbox Code Playgroud)