from os import urandom
from PIL import Image
import io
for y in range((len(array2) -1), -1, -1):
decrypted_initial = decrypt(array2[y], key)
if y > 0:
decrypted_cipher = decrypt(decrypted_initial, array2[(y -1)])
if y == 0:
decrypted_cipher = decrypt(decrypted_initial, fixed_initialization_vector)
immage_array.append(decrypted_cipher)
immage_array = [x for sets in immage_array for x in sets] #The list is all zeros since the image is all black.
for i in range(1000):
print (immage_array[i]) #1000 zeroes printed.
if immage_array == myMessage: #Comparing the input hexocde for the encryption and output hexcode from the decryption.
print("Yay.") #Print successful.
image = Image.open(io.BytesIO(bytes(immage_array))) #Not sure what this does exactly. I am just trying to get the hexcode to output as an image file.
image.save(output.png)
我想在图像上执行链接块密码,这是代码的一部分。我已经能够获取图像的十六进制代码,使用分组密码对其进行加密,并对其进行解密。然后,我将解密后的十六进制代码与原始输入的十六进制代码进行比较,并获得成功的匹配。虽然十六进制代码是以列表而不是字节数组的形式返回的,但if语句仍将它们识别为相等。我很难将十六进制代码转换回图像。为什么十六进制代码输出失败?
我得到这个错误。 OSERROR:在0x039F1090>
的图像是用于测试目的的所有黑象素,可以很容易确认我已确认为与输入相同的十六进制代码的完整性不能识别图像文件< _io.BytesIO对象。
什么阻止我将十六进制码转换回图像?我尝试过寻找可行的例子,但我从来没有能够完全理解它为什么起作用。这是我的逻辑。
immage_array是一个列表==(0,0,0,0,...,N)
字节()#turns所有整数0的immage_array列表到字节数组的所有组成X00的。
io.BytesIO()函数需要由Image.open()函数处理字节数组。
然后我将字节数组作为对象存储在变量图像中。
image.save(output.png)save函数将文件名作为参数。使用图像对象。
我诚实地试图找出逻辑失败的地方。我希望能够解释如何将(0,0,0,...,n)列表转换为图像。是的,我知道,我已经看到了其他堆栈溢出的例子。我想知道为什么我的实施失败。
如果你告诉我们你正在使用哪个图像类 –
bytes.IO对象需要是格式正确的图像文件的内容。不知道你在创建immage_array数组,但它看起来并不像图像的内容。你确定你不是指'PIL.Image.frombytes'构造函数吗? –
我使用myMessage = list(Image.open('myfile.png','r')。getdata())获取了一个图像文件的十六进制代码,然后通过我自己写的连锁分组密码算法传递给它,原来的名单回来。我用if语句来比较它们。 – Dave