Created
April 6, 2021 18:02
-
-
Save stephanie-w/d07b1f70868d60dc980b6232b7aa03f1 to your computer and use it in GitHub Desktop.
Revisions
-
stephanie-w created this gist
Apr 6, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import numpy as np from PIL import Image message = "Hello World!" # Encode the message in a serie of 8-bit values b_message = ''.join(["{:08b}".format(ord(x)) for x in message ]) b_message = [int(x) for x in b_message] b_message_lenght = len(b_message) # Get the image pixel arrays with Image.open("cover.png") as img: width, height = img.size data = np.array(img) # Flatten the pixel arrays data = np.reshape(data, width*height*3) # Overwrite pixel LSB data[:b_message_lenght] = data[:b_message_lenght] & ~1 | b_message # Reshape back to an image pixel array data = np.reshape(data, (height, width, 3)) new_img = Image.fromarray(data) new_img.save("cover-secret.png") new_img.show()