If you erase lower two bits in the red value, you can clear space for hiding values 0–4.

```
for p in getPixels(picture):
# Clear out the red 2xLSB
r = getRed(p)
setRed(p,r-(r%4))
```
If you erase the lower two bits from red, green, and blue, you can save six bits. Six bits can encode 64 values. That’s enough to encode all 27 letters, both upper and lower case.

(a) Write a function to input a picture and a string. Save each character in the string in a pixel of the picture, by saving it across the least significant two bits in each of red, green, and blue. Can you tell the difference between the original picture and the picture with the
encoded text message?

No, it’s highly unlikely someone could tell a difference between the original and the modified picture.

Note: The below method special cases for the space character, as otherwise messages cannot include spaces, this is possible to do as six bits allows for additional space beyond the 54 needed for upper and lower case letters.

(b) Now write a function to decode the original text.

(a) ```
def encodeMessage(picture, message):
#Go through all pixels and erase the lower two bits
for p in getPixels(picture):
# Clear out the red 2xLSB
r = getRed(p)
setRed(p,r-(r%4))
# Clear out the green 2xLSB
g = getGreen(p)
setGreen(p,g-(g%4))
# Clear out the blue 2xLSB
b = getBlue(p)
setBlue(p, b-(b%4))

pixels = getPixels(picture)
for charIndex in range(0, len(message)):
characterVal = (ord(message[charIndex])-65)

#Special case space symbol
if ord(message[charIndex])==32:
characterVal = 55

#Convert the number into a binary representation
binaryValues = [0,0,0,0,0,0]
index = 5
while characterVal>0:
binaryValues[index] = ((characterVal%2))
characterVal = characterVal/2
index= index-1

#Encode the values into the picture
redVal = binaryValues[1]
redVal = redVal+ 2*binaryValues[0]

greenVal = binaryValues[3]
greenVal = greenVal+ 2*binaryValues[2]

blueVal = binaryValues[5]
blueVal = blueVal+ 2*binaryValues[4]

r = getRed(pixels[charIndex])
setRed(pixels[charIndex],r+redVal)
g = getGreen(pixels[charIndex])
setGreen(pixels[charIndex],g+greenVal)
b = getBlue(pixels[charIndex])
setBlue(pixels[charIndex],b+blueVal)

return picture
```

(b) ```
def decodeMessage(picture):
secretMessage = ""
charIndex = 0
for p in getPixels(picture):
r = getRed(p)%4
g = getGreen(p)%4
b = getBlue(p)%4

binaryValues = [0,0,0,0,0,0]

#Translate the values into binary
if not r==0:
if r==1:
binaryValues[1] = 1
elif r==2:
binaryValues[0] = 1
elif r==3:
binaryValues[0]=1
binaryValues[1]=1
if not g == 0:
if g==1:
binaryValues[3] = 1
elif g==2:
binaryValues[2] = 1
elif g==3:
binaryValues[2]=1
binaryValues[3]=1
if not b == 0:
if b==1:
binaryValues[5] = 1
elif b==2:
binaryValues[4] = 1
elif b==3:
binaryValues[4]=1
binaryValues[5]=1


binaryValues.reverse()

characterValue = 0
multiple = 1
for index in range(0, 6):
characterValue = characterValue+(multiple)*binaryValues[index]
multiple = multiple*2

#Special Case Space value
if not characterValue==55:
secretMessage = secretMessage+ (chr(characterValue+65))
else:
secretMessage = secretMessage + " "

return secretMessage
```

Note: Unless you pass along a message length, the end of the message will have a great number of extra capital A values.

Computer Science & Information Technology

You might also like to view...

Which of the following about the GROUP BY clause if FALSE?

A) By using the GROUP BY clause, you can combine records with identical values in a specified field list into a single record. B) The GROUP BY clause allows you to limit the results of your query by specifying criteria that field values must meet without using that field to group the data mathematically C) The GROUP BY clause needs to be used with Sum, Count, and so on to display aggregated data. D) The GROUP BY clause can be used to summarize duplicate data.

Computer Science & Information Technology

While the concept of privacy has been debated by the courts and legal systems for nearly two centuries, the strongest definition of the concept came about when The Privacy Act was passed. This happened in the year _______.

a. 1916 b. 1974 c. 1986 d. 1888

Computer Science & Information Technology