所以我的程序是一个速记程序,它将图像插入到另一个图像中,并且我试图在将数据插入到封面图像中之前加密数据。但是,大多数加密模块期望字符串,我试图传递整数。可以加密整数吗?
我试过转换成字符串然后加密,但加密是特殊字符和字母,所以转换回整数插入是不可能的。
任何人都知道我是否可以以某种方式加密一个整数?它不一定非常安全。
我尝试添加加密在这里:
for i in range(0,3):
#verify we have reached the end of our hidden file
if count >= len(Stringbits):
#convert the bits to their rgb value and appened them
for rgbValue in pixelList:
pixelnumbers1 = int(''.join(str(b) for b in rgbValue), 2)
#print pixelnumbers1
rgb_Array.append(pixelnumbers1)
pixels[x, y] = (rgb_Array[0], rgb_Array[1], rgb_Array[2])
print "Completed"
return imageObject.save(output)
我一直在试图加密pixelnumbers1
然后将它添加但是pixels[x, y]
需要一个整数。
下面是套内的其余代码:
def write(mainimage, secret, output):
#string contains the header, data and length in binary
Stringbits = dcimage.createString(secret)
imageObject = Image.open(mainimage).convert('RGB')
imageWidth, imageHeight = imageObject.size
pixels = imageObject.load()
rgbDecimal_Array = []
rgb_Array = []
count = 0
#loop through each pixel
for x in range (imageWidth):
for y in range (imageHeight):
r,g,b = pixels[x,y]
#convert each pixel into an 8 bit representation
redPixel = list(bin(r)[2:].zfill(8))
greenPixel = list(bin(g)[2:].zfill(8))
bluePixel = list(bin(b)[2:].zfill(8))
pixelList = [redPixel, greenPixel, bluePixel]
#for each of rgb
for i in range(0,3):
#verify we have reached the end of our hidden file
if count >= len(Stringbits):
#convert the bits to their rgb value and appened them
for rgbValue in pixelList:
pixelnumbers1 = int(''.join(str(b) for b in rgbValue), 2)
#print pixelnumbers1
rgb_Array.append(pixelnumbers1)
pixels[x, y] = (rgb_Array[0], rgb_Array[1], rgb_Array[2])
print "Completed"
return imageObject.save(output)
#If we haven't rached the end of the file, store a bit
else:
pixelList[i][7] = Stringbits[count]
count+=1
pixels[x, y] = dcimage.getPixel(pixelList)
大多数加密系统可以使用任意二进制数据,字符串或两者兼有。 “整数”不是一个他们可以处理的概念,因为整数的格式在一个系统之间变化很大。您始终可以将整数转换为字符串,然后对其进行加密,然后将其加密。加密数据通常是原始二进制文件,并将其字符串化需要使用Base64或类似的编码。 – tadman
整数,字符串等,只是二进制值的解释。如果你可以加密一种类型,你可以全部加密。 –
@tadman你是什么意思的“烤它”? –