Created
April 6, 2021 18:15
-
-
Save stephanie-w/60c800df360f19e0ad1a1beafbe00b4a 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,22 @@ from PIL import Image import numpy as np cover = Image.open("cover.png") data_c = np.array(cover) # Convert image to full black and white and resize to cover image secret = Image.open("qr-secret.png").convert('1') secret = secret.resize(cover.size) data_s = np.array(secret, dtype=np.uint8) # Extract 2nd LSB (7th bit from left) from cover image # The binary operation performed is : pixel >> 8-k & 1 (with k the kth bit to extract starting from 1) # same as pixel // 2**(8-k) & 1 bit = np.bitwise_and(np.right_shift(data_c, 1), 1) # Rewrite cover LSB with bit from secret xored with LSBs res = data_c & ~1 | bit ^ data_s new_img = Image.fromarray(res).convert("L") new_img.save("cover-secret.png") new_img.show()