更新對不起特此完整的錯誤消息,一些Python幫助: 文件 「C:\ XXX \ crypto.py」 26行 ELIF LEN(塊)%16 = 0:需要對indentationerror
IndentationError:預期預期的塊
這是完整的錯誤消息。
我的腳本引發了一個IndentationError
,你能幫我解決嗎?
import os, random
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
def encrypt(key, filename):
chunksize = 64*1024
outputFile = "(encrypted)"+filename
filesize = str(os.path.getsize(filename)).zfill(16)
IV = ''
for i in range(16):
IV += chr(random.randint(0, 0xFF))
encryptor = AES.new(key, AES.MODE_CBC, IV)
with open(filename, 'rb') as infile:
with open(outputFile, 'wb') as outfile:
outfile.write(filesize)
outfile.write(IV)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
elif len(chunk) % 16 !=0:
chunk += ' ' * (16 - (len(chunk) % 16))
outfile.write(encryptor.ecrypt(chunk))
def decrypt(key. filename):
chunksize = 64*1024
outputFile = filename[11:]
with open(filename, 'rb') as infile:
filesize = long(infile.read(16))
IV = infile.read(16)
decryptor = AES.new(key, AES.MODE_CBC, IV)
with open(outputFile, 'wb') as outfile:
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
outfile.write(decryptor.decrypt(chunk))
outfile.truncate(filesize)
def getKey(password)
hasher = SHA256.new(password)
return hasher.digest()
def Main():
choice = raw_input("Would you like to (E)ncrypt or (D)ecrypt?: ")
if choice == 'E':
filename = raw_input("File to encrypt: ")
password = raw_input("Password: ")
encrypt(getKey(password), filename)
print "Done."
elif choice == 'D':
filename = raw_input("File to decrypt")
password = raw_input("Password: ")
decrypt(geetkey(password), filename)
print "Done."
else:
print "No option selected, closing..."
if _name_ == '_name_':
Main()
當您尋求錯誤搜索幫助時,請始終包含完整的錯誤消息。它包含有關錯誤發生的原因和*哪裏的信息。 – timgeb
因爲我是新的,我不知道什麼是空的塊。你知道如何解決它嗎?該錯誤說,順便說一句,它在第26行。這一個:elif len(塊)%16!= 0 :.我需要改變什麼?謝謝! – dyionisus
看到我發佈的答案,它解決了這個問題。 –