# 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:  Example 2. more red: Example 3. crop two images of different sizes:  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/