python - 在 linux python 中运行文件时遇到问题

标签 python linux python-2.7 kali-linux

<分区>

当我键入 python cracked.py 打开文件时,文件没有打开并转到新行。为什么要这样做?这是我要运行的代码:

import crypt 

def testPass(cryptPass):
    salt = cryptPass[0:2]
    dictFile = open('dictionary-1.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('/root/homework/HomeworkW8.zip')
    for line in passFile.readlines():
        if ":" in line:
            user = line.split(':')[0]
            cryptPass = line.split(':')[1].strip(' ')
            print "[*] Crackin Password For: "+user
            testPass(cryptPass)

if __name__  == "__main__":
    main()

最佳答案

passFile 包含一个 zip 文件。您无法读取 zip 文件。您需要首先解压缩“HomeworkW8.zip”文件并打开其中的文件(例如 .txt 或 .csv 或 .xls 等)。

如果你想知道如何解压缩文件,这里是链接 Unzipping files in python

关于python - 在 linux python 中运行文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54897421/

相关文章:

Python CherryPy 调用 HTML 文件

python - 如何追加屏蔽数组

linux - 用 shell 脚本比较 2 个文件

python - 从文件中读取小端并转换为十进制

python - 从namedtuple中获取特定对象的对象名

python - 按索引对 numpy.array 行进行排序

用于跟踪重复项的 python 数据类型

Python删除字符直到字母或数字

c - 如何在单独的线程中更新 GTK+ GUI 的一部分,该线程不断从另一个进程读取数据?

linux - 如何修复 Trac 安装