Review of JavaScript function & steganography

The previous post: review of JavaScript syntax basics

Function

A function consists of three elements:

  • function name
  • parameter
  • return

Example 1. frame an image with black border:

bb2

Example 2. more red:

red

Example 3. crop two images of different sizes:

c1c2

Example 4. enlarge the image:

note: the top left pixel is at position (0,0)

http://www.dukelearntoprogram.com/course1/enlarge2/

 

Steganography

  • Rationale

The idea is that you have image A and image B, and you want to hide image B inside A. Suppose A is 10111100, B is 11011001. You would take 1011 from A and 1101 from B (use 16=2^4 to get those numbers). Then, we can combine them into 10111101 and get the new image with a hidden image in it!

pa: pixel for image A

npa: the new pixel for image A

pb: pixel for image B

npb: the new pixel for image B

npa. setRed(Math.floor(pa/16) * 16)
npb. setRed(Math.floor(pb.getRed()/16))
  • complete coding example:

http://www.dukelearntoprogram.com/course1/steganography/

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s