解密函数最后是lauching错误

时间:2017-05-08 03:17:49

标签: python

我想在python中创建一个解密脚本,我的函数filename = allfiles();返回路径所在的文件,但我尝试解密我的文件启动我的错误,如下所示。我该如何解决?我正在使用python 2.7

Traceback (most recent call last):   
   File "F:\bug_bounty\decrypt.py", line 41, in <module>
     if os.path.basename(filename).startswith("(encrypted)"):
   File "C:\Python27\lib\ntpath.py", line 208, in basename
     return split(p)[1]
   File "C:\Python27\lib\ntpath.py", line 180, in split
     d, p = splitdrive(p)
   File "C:\Python27\lib\ntpath.py", line 116, in splitdrive
     normp = p.replace(altsep, sep)
AttributeError: 'list' object has no attribute 'replace'

代码:

from Crypto.Hash import SHA256
from Crypto.Cipher import AES
import os
import random
import sys


def decrypt(key, filename):
    outFile = os.path.join(os.path.dirname(filename),
                           os.path.basename(filename[11:]))
    chunksize = 64 * 1024
    with open(filename, 'rb') as infile:
        filesize = infile.read(16)
        IV = infile.read(16)

        decryptor = AES.new(key, AES.MODE_CBC, IV)

        with open(outFile, 'wb') as outfile:
            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break

                outfile.write(decryptor.decrypt(chunk))

            outfile.truncate(int(filesize))


def allfiles():
    allFiles = []
    for (root, subfiles, files) in os.walk(os.getcwd()):
        for names in files:
            allFiles.append(os.path.join(root, names))

    return allFiles


password = 'M4st3rRul3zs'
filename = allfiles();
for files in filename:
    if os.path.basename(filename).startswith("(encrypted)"):
       print "%s is already encrypted" %filename
       pass
    else:  
        decrypt(SHA256.new(password).digest(), filename)
        print "Done decrypting %s" %filename
        """os.remove(filename)"""

0 个答案:

没有答案