Last active
September 11, 2021 08:12
-
-
Save lorenzobn/aebbe041262b1eead982a374f34b0a9d to your computer and use it in GitHub Desktop.
Snippet taken from main.py with a focus on LSB hiding function
This file contains 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 characters
start_pixel = get_num_rand(used_pixels, num_of_pixels) | |
while byte_written != len(input_data): | |
bit_i = 0 | |
while bit_i != 8: | |
px = matrix[start_pixel] | |
# colors: Red, Green and Blue | |
for c in range(conf[0], conf[1]): | |
if bit_i == 8: | |
break | |
# Because of Least Significant Bit, we want to modify the last bit of every color | |
color = matrix[start_pixel][c] | |
lsb = color&1 | |
# Here, we just use bit manipulation to modify the last bit of the color number | |
if lsb != int(binary_enc[(byte_written*8)+bit_i]): | |
color = color>>1 # erase last bit | |
color = color<<1 # zero last bit | |
if lsb == 0: # it means that byte[bit_i]=1, so I need to encode 1 | |
color = color|1 | |
matrix[start_pixel][c] = color | |
bit_i += 1 | |
start_pixel = get_num_rand(used_pixels, num_of_pixels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment