View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Steganography

Steganography is about hiding messages in ways that can't be detected without knowing that the message is there. There are some pretty fun ways to do this in Media Computation. This example hides black and white messages inside one bit of the red value of pixels.

The zip contains input pictures (message and picture), an encoded picture, and the decoded message, and the .py file. Note that we developed this for the Second Edition, so it presumes indices start at 0.

steg-example.zip

def encode(msgpic,original):
  # Assume msgpic and original have same dimensions
  # First, make all red pixels even in original
  for px in getPixels(original):
    # Using modulo operator to test oddness
    if (getRed(px) % 2) == 1:
      setRed(px, getRed(px) - 1)
  # Second, wherever there's black in msgpic
  # make odd the red in the corresponding original pixel
  for x in range(0,getWidth(original)):
    for y in range(0,getHeight(original)):
      msgPx = getPixel(msgpic,x,y)
      origPx = getPixel(original,x,y)
      if (distance(getColor(msgPx),black) < 10.0):
        # It's a message pixel! Increase red in original
        setRed(origPx, getRed(origPx)+1)
  #Message is now in original. Be sure to save as .png or .bmp!

def decode(encodeImg):
  # Takes in an encoded image. Return the original message
  message = makeEmptyPicture(getWidth(encodeImg),getHeight(encodeImg))
  for x in range(0,getWidth(encodeImg)):
    for y in range(0,getHeight(encodeImg)):
      encPx = getPixel(encodeImg,x,y)
      msgPx = getPixel(message,x,y)
      if (getRed(encPx) % 2) == 1:
        setColor(msgPx,black)
  return message



Links to this Page