Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What would a python code look like that would find a hidden message in a pixle a

ID: 3865512 • Letter: W

Question

What would a python code look like that would find a hidden message in a pixle ated picture and save it to a new file look like? Below is the guidelines for this question and the links to download the images will be below

link1 http://benjdd.com/courses/cs110/summer-2017/assignments/hidden-message/res/small.ppm

link2 http://benjdd.com/courses/cs110/summer-2017/assignments/hidden-message/res/message-1.ppm

link3 http://benjdd.com/courses/cs110/summer-2017/assignments/hidden-message/res/message-2.ppm

Hidden Messages We briefly discussed the PPM (sometimes also referred to as pbm) image format in class. If you need a refresher on the format take a look at the course materials. You may also find these resources useful PPM Format Specification Wikipedia page PPMPGWPBM image files The first line of a ppm file specifies the exact format the second line specifie the maximum RGB value, and the third specifies the width and height. Technically, comment lines starting with g are allowed in a PPM image, but you may assume that the PPM images will not have any comments. From the fourth line and on, the ASClI representation of each red. green, and blue pixel value in the image in represented in text. For the purposes of this assignment, you may assume that The ppm (or pbm) images you will read in will be specified in asdi . There will be no comments. Thus, there will be exactly 3 lines of metadata-info and the rest will be the pixcels . The rows and columns in the asci text will be aligned the same way the actual pixels are in the image In this assignment, you will be writing a program that reads in a ppm image and extracts hidden messages from them In total your program should read in 3 different input values,using Ere The first shall be the name of the file containing the ppm image to find the mesage in. The second will the name of a (new) file to save the modified image into. The third will request the color channel to extract (red green, or blue). You should use the grestt function to grab these values. An example of reading these values in looks like the following If the last value is not red green or blue, you should report a complaint to the console and then exit the program Using these values your programs will extract the hidden message from the provided color channel For each pixel, you should check the brightness value of the color that corresponds to the channel. If the value is non-zero, make the value of the pixel the max (255) If t is zero leave as-is. The brightness values of the remaining channels should be changed to zero for all piels If an limage with a hidden message is passed into the program this will reveal it The original lmage should remain un-modified The adjusted image will be written to the output Ee You must use 2D lists to represént the rows and columns of the text images!

Explanation / Answer

''' PIL_HideText1.py hide a short message (255 char max) in an image the image has to be .bmp or .png format and the image mode has to be 'RGB' ''' from PIL import Image def encode_image(img, msg): """ use the red portion of an image (r, g, b) tuple to hide the msg string characters as ASCII values red value of the first pixel is used for length of string """ length = len(msg) # limit length of message to 255 if length > 255: print("text too long! (don't exeed 255 characters)") return False if img.mode != 'RGB': print("image mode needs to be RGB") return False # use a copy of image to hide the text in encoded = img.copy() width, height = img.size index = 0 for row in range(height): for col in range(width): r, g, b = img.getpixel((col, row)) # first value is length of msg if row == 0 and col == 0 and index
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote