Skip to content

Instantly share code, notes, and snippets.

@lorenzobn
Last active September 11, 2021 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzobn/dca3aaef341965c32d207ee6d23185ee to your computer and use it in GitHub Desktop.
Save lorenzobn/dca3aaef341965c32d207ee6d23185ee to your computer and use it in GitHub Desktop.
Snippet taken from main.py with a focus on LSB retrieving function
while (end == False):
while (bit_i >= 0):
px = matrix[start_pixel]
# colors: Red, Green and Blue
for c in range(conf[0], conf[1]):
if bit_i >= 0:
# We are getting the LSB of the pixel color, and then we shift it to the left accordingly
byte += (px[c]&1)<<bit_i
bit_i -= 1
else:
break
start_pixel = get_num_rand(used_pixels, num_of_pixels)
if start_pixel>=num_of_pixels:
break
# decoded 1 byte
message += chr(byte)
# have I encountered the eof_marker? If yes, the decoding process is done
if message[-len(EOF_MARKER):] == EOF_MARKER:
end = True
byte = 0
bit_i = 7
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