首页 > 解决方案 > Python crypt() 脚本无法正确编译

问题描述

知道为什么这不能正确编译吗?

它应该将计算的_salt_hash 与加密的密码进行比较,如果它们匹配,那么它将打印匹配的单词。目前有错误AttributeError: 'list' object has no attribute 'strip'。如何完成代码,以便向我显示匹配的单词?

(如果在我的程序中没有正确缩进,请忽略)

import crypt    


with open("PWD", 'r') as passwd, open("dictionary", 'r') as wordfile:
   
    file = passwd.readlines()
    lines = wordfile.readlines()
    
    for i in file: 
        salt_hash = file.strip()
        salt = salt_hash[0:2] 

    for line in lines:               
         word = line.strip()
        calculated_salt_hash = crypt.crypt(word, salt)
        if calculated_salt_hash == salt_hash:
            print("Found:", word)
            break 

标签: pythonpython-3.xhashcryptsaltedhash

解决方案


推荐阅读