所以我的程序是一個速記程序,它將圖像插入到另一個圖像中,並且我試圖在將數據插入到封面圖像中之前加密數據。但是,大多數加密模塊期望字符串,我試圖傳遞整數。可以加密整數嗎?
我試過轉換成字符串然後加密,但加密是特殊字符和字母,所以轉換回整數插入是不可能的。
任何人都知道我是否可以以某種方式加密一個整數?它不一定非常安全。
我嘗試添加加密在這裏:
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你是什麼意思的「烤它」? –