@timmy_i_chen/

secret announcement

Python

This is a puzzle that contains a secret announcement. Use your steganography and reverse engineering skills to figure it out!

fork
loading
Files
  • main.py
  • out.png
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PIL import Image

# to start, click on out.png and download the image
# (don't download the jpg from the newsletter - see last comment)

# the original two files are missing
# can you reverse engineer this program
# to find the hidden message in the picture?
# hint: steganography
public = Image.open("comp.jpg").convert("RGB")
secret = Image.open("secret.jpg").convert("RGB")

out = Image.new("RGB", (600, 600))

all_except_LSB_mask = 254 # binary: 11111110
shift_amt = 7

for x in range(600):
  for y in range(600):
    secret_pix = secret.getpixel((x, y))
    public_pix = public.getpixel((x, y))

    secret_red = secret_pix[0] >> shift_amt
    secret_green = secret_pix[1] >> shift_amt
    secret_blue = secret_pix[2] >> shift_amt

    public_red = public_pix[0] & all_except_LSB_mask
    public_green = public_pix[1] & all_except_LSB_mask
    public_blue = public_pix[2] & all_except_LSB_mask
    
    final = (
      secret_red + public_red,
      secret_green + public_green,
      secret_blue + public_blue
    )

    out.putpixel((x, y), final)

# must be png! no jpg because compression is evil :(
out.save('out.png')