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()