Effective Programming in C and UNIX Lab 5 Image Encryption with BMP Images Due Date: Saturday March 28th, 2009 by 11:59pm

Similar documents
Simple Image File Formats

Cyber Security Workshop Encryption Reference Manual

Safer data transmission using Steganography

STEGANOGRAPHY: TEXT FILE HIDING IN IMAGE YAW CHOON KIT CA10022

Username: Lab date and time: CSC 101: Lab #11 Manual and Report: Cryptography Due date: 5:00pm, day after lab session

Data Storage 3.1. Foundations of Computer Science Cengage Learning

A Robust and Lossless Information Embedding in Image Based on DCT and Scrambling Algorithms

A Concept of Digital Picture Envelope for Internet Communication

Extracting, Storing And Viewing The Data From Dicom Files

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Comparison of different image compression formats. ECE 533 Project Report Paula Aguilera

PowerPoint Interface Menu Bars Work Area Slide and Outline View TASK PANE Drawing Tools

UNIVERSITY OF CALICUT

Fast Arithmetic Coding (FastAC) Implementations

Digital Image Fundamentals. Selim Aksoy Department of Computer Engineering Bilkent University

A Proposal for OpenEXR Color Management

File transfer clients manual File Delivery Services

Microsoft Picture Manager. Picture Manager

PaperlessPrinter. Version 3.0. User s Manual

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

REFERENCE GUIDE 1. INTRODUCTION

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

encoding compression encryption

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Smithsonian Institution Archives Guidance Update SIA. ELECTRONIC RECORDS Recommendations for Preservation Formats. November 2004 SIA_EREC_04_03

How To Write Portable Programs In C

FontEditor V1.0 manual

Viewing and editing of Typhoon scanner images from 1D, 2D, and DiGE experiments at CIAN

ART 170: Web Design 1

Chapter 3 Graphics and Image Data Representations

Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration

Digital Versus Analog Lesson 2 of 2

CSIS Security Research and Intelligence Advisory Microsoft GDI+ Integer division by zero flaw handling.ico files VU# CVE

A deeper look at Inline functions

Third Southern African Regional ACM Collegiate Programming Competition. Sponsored by IBM. Problem Set

DNA Data and Program Representation. Alexandre David

TRUSTED DOWNLOAD. Background

Package png. February 20, 2015

Fixplot Instruction Manual. (data plotting program)

MassArt Studio Foundation: Visual Language Digital Media Cookbook, Fall 2013

Instructions for Creating a Poster for Arts and Humanities Research Day Using PowerPoint

ANALYSIS OF THE COMPRESSION RATIO AND QUALITY IN MEDICAL IMAGES

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

MMGD0203 Multimedia Design MMGD0203 MULTIMEDIA DESIGN. Chapter 3 Graphics and Animations

Fireworks CS4 Tutorial Part 1: Intro

A Basic Summary of Image Formats

1 Abstract Data Types Information Hiding

OpenEXR Image Viewing Software

ACTIVE CONTENT MANAGER (ACM)

Lesson 10: Video-Out Interface

The use of binary codes to represent characters

Plain-paper digital Fax/Copier/Printer/Scanner Scanner and Fax Guide

The Hexadecimal Number System and Memory Addressing

LEAGUE OF WOMEN VOTERS NAME & LOGO GUIDELINES

Seeing in black and white

Chapter 4: Computer Codes

Chair for Network Architectures and Services Department of Informatics TU München Prof. Carle. Network Security. Chapter 13

Freescale Embedded GUI Converter Utility 2.0 Quick User Guide

MASKS & CHANNELS WORKING WITH MASKS AND CHANNELS

Computer Organization

Using Image J to Measure the Brightness of Stars (Written by Do H. Kim)

Steganography Detection for Digital Forensics

Cryptography: Motivation. Data Structures and Algorithms Cryptography. Secret Writing Methods. Many areas have sensitive information, e.g.

w w w. g e o s o f t. c o m

Sprites in Block ROM

Secure Network Communication Based on Text-to-Image Encryption

Cardless Cash Access Using Biometric ATM Security System Neenu Preetam. I 1, Harsh Gupta 2

How to Send Video Images Through Internet

First Bytes Programming Lab 2

designed and prepared for california safe routes to school by circle design circledesign.net Graphic Standards

Petrel TIPS&TRICKS from SCM

Lab 5: BitTorrent Client Implementation

MULTIMEDIA INSTALLING THE MULTIMEDIA UPGRADE

Course Project Lab 3 - Creating a Logo (Illustrator)

Choosing a digital camera for your microscope John C. Russ, Materials Science and Engineering Dept., North Carolina State Univ.

Barcodes principle. Identification systems (IDFS) Department of Control and Telematics Faculty of Transportation Sciences, CTU in Prague

What Resolution Should Your Images Be?

Written examination in Computer Networks

Practical Attacks on Digital Signatures Using MD5 Message Digest

Credit Card Processing

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

University of Pennsylvania Department of Electrical and Systems Engineering Digital Audio Basics

Firefox, Opera, Safari for Windows BMP file handling information leak. September Discovered by: Mateusz j00ru Jurczyk, Hispasec Labs

Introduction to UNIX and SFTP

Digital Preservation. Guidance Note: Graphics File Formats

Photoshop- Image Editing

Gear View Basic. User Help. Version Written by: Product Documentation and R&D Date: August 2015 LX-DOC-GVB UH-EN-REVA

FIRST Robotics Competition (FRC) Application Programming Interface (API) Specification For Machine Vision

Using MATLAB to Measure the Diameter of an Object within an Image

Digital Forensics. Tom Pigg Executive Director Tennessee CSEC

The following is an overview of lessons included in the tutorial.

Reviewer s Guide. Morpheus Photo Animation Suite. Screenshots. Tutorial. Included in the Reviewer s Guide:

A Guide to Microsoft Paint (Windows XP)

Microsoft Word Quick Reference Guide. Union Institute & University

A Secure Data Transmission By Integrating Cryptography And Video Steganography

Scanning Scanning images. cover

Chapter 11 Security+ Guide to Network Security Fundamentals, Third Edition Basic Cryptography

How to Make the Most of Excel Spreadsheets

Transcription:

15-123 Effective Programming in C and UNIX Lab 5 Image Encryption with BMP Images Due Date: Saturday March 28th, 2009 by 11:59pm Background: Encryption is a method used to protect data from intruders during transmission. The idea of data encryption is to scramble data using a specific key, so attackers would need to know the key to decrypt the data. The reverse of data encryption is called decryption. Decryption algorithm will recreate the original data file. For example, a naïve encryption of an ASCII file is to encrypt each character just by adding 1 to each character. That is replacing each character by its successor in the ASCII table. So a b, b c,, t u. So the word bat would be encrypted as cbu. Now applying the decryption algorithm (or just subtracting one from each of the encrypted characters cbu or by replacing with its predecessor will produce the original word bat. Although there are number of research results available on image encryption, our goal in this assignment is not to use one of the more advanced algorithms, but try out number of simple algorithms, some of your choosing, that would allow us to work with binary files, do some bit manipulations, encode and decode image files. For simplicity we will consider only the uncompressed image formats like BMP (jpeg and gif are compressed forms of images). Here is some background information about BMP s. The BMP file format: The images we are planning to encrypt are in the BMP file format, which is one of the most popular uncompressed file formats for images. Note that you will need to find a way to view the images for this assignment. I recommend writing and testing the program on Andrew Unix and using SSH File Transfer Client to view the files on the local machine using MS Paint to see if the encryption is working. If you are working on a Linux cluster machine, you can also use the command display ($ display image.bmp) to view the image assuming x terminal is installed. Your program should be able to encrypt any bitmap file of size n by m pixels. The actual size of a BMP image of n by m pixels is given by (3 n m + 54+ some extra bytes) bytes. Each BMP file allocates 54 bytes for header information, and each pixel takes up 3 bytes for Red, Green and Blue (RGB). Extra bytes may be used for padding purposes. We should not encrypt the BMP header or the extra bytes. You should just read the first 54 bytes into an array, and when you write it out again, you should just write the header bytes unchanged. The pixels of a color image are stored in RGB format, which means that each pixel is represented by three bytes, one for red, one for green, and one for blue. One byte can store numbers in the range 0-255. So the color red is (255, 0, 0) and green is (0, 255, 0). And (128, 0, 0) make dark red, and (255, 0, 255) makes purple since purple is red + blue. It is important to note that the pixels are stored from left to right and from bottom to top (upside down!). So the first m groups of three bytes (3 m bytes) in the file (after the 54-byte header) correspond to the bottom row of the image, and the last m groups of three bytes correspond to the top row. Also make sure that you figure out whether image has extra bytes or not.

The form of a bit map image are given as follows. You can simply think of the file structure as Header 54 bytes R G B R G B R G B extra bytes The left most RGB is the lower right pixel of the image and last RGB is the upper left pixel of the image. Suggested Data Structure: We really do not need any special data structure to do this program. Just a simple array of characters is good enough to store all the bytes in the file. However, maintaining some of the image attributes in a struct such as typedef struct { char* data; char* header; int height; int width; int size; } Bitmap; will help us perform the necessary operations on the image. For example, we can invert the image or shift pixel rows of the image etc. The data field inside the bmp struct will contain the array of bytes that make up the image. The header field will contain the header information and will not change in any operations. Each field requires allocation of dynamic memory as needed. The structure of the 54 byte header of a BMP file is as follows. The first 14 bytes are allocated for

typedef struct { unsigned short int type; /* BMP type identifier */ unsigned int size; /* size of the file in bytes*/ unsigned short int reserved1, reserved2; unsigned int offset; /* starting address of the byte */ } HEADER; The next 40 bytes are reserved for a structure as follows. typedef struct { unsigned int size; /* Header size in bytes */ int width,height; /* Width and height in pixels */ unsigned short int planes; /* Number of color planes */ unsigned short int bits; /* Bits per pixel */ unsigned int compression; /* Compression type */ unsigned int imagesize; /* Image size in bytes */ int xresolution,yresolution; /* Pixels per meter */ unsigned int ncolors; /* Number of colors */ unsigned int importantcolors; /* Important colors */ } INFOHEADER; The Assignment In this assignment we plan to complete number of functions so that we can read, write, encrypt and decrypt images. Part 1 In this part of the assignment you are simply trying to read, store and write a BMP image file. You are to complete the following functions. //Read the image into mybmp. You must allocate just enough memory to hold the image bytes. This can be done by first reading the header and figuring out what the size of the image is void readimage(char* infile, Bitmap* mybmp); // writes the encrypted image to outfile void writeimage(char* outfile, Bitmap* mybmp); You also need to complete the main program so that when the command $./lab5 file1 file2 It will simply read BMP file1 and write to BMP file2. When you open file2 using an image viewer, you should see the same image as in file 1. This will allow us to make sure, we can read and write BMP images. Part 2 In this part of the assignment you are to write a non-trivial encryption algorithm to encrypt your image. You should also write a decryption algorithm to recover the original image. See Suggested Algorithms area below to see some suggestions. A trivial algorithm is one

that just negate the bits or uses a flag to mask the bits. A non-trivial algorithm will try to distort the image while keeping some attributes. You are to write at least the following functions: // encrypt the image using a non-trivial algorithm. void encrypt(bitmap* mybmp); // decrypt the image. You are free to use the inverse of the encrypt void decrypt(bitmap* mybmp); You also need to complete the main program to handle -e and -d flags $./lab5 e file1 file2 //encrypt file1 and write to file2 $./lab5 -d file2 file1 // decrypt file2 and write to file1 Part 3 In this part of the assignment you are to write a simple rotate function that will rotate the current image by 180. This is not difficult if you really think about how the image is stored. //rotate makes the image upside down or rotation by 180 degrees void rotate(bitmap *bitmap); You also need to complete the main program to handle -r flags $./lab5 -r file1 file2 // rotate file1 and write to file2 Part 4 In this part of the assignment you are to implement a known algorithm that allows us to hide a message inside an image. Steganography is the art and science of writing hidden messages in such a way that no-one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity[source: Wikipedia] In this part we will only test the following two images. //This will apply the following algorithm to an image. Remove all but last two bits of each color component. Make the resulting image 85 times brighter void coolalgorithm(bitmap* mybmp); This algorithm will take this image and convert to this image when you apply the above algorithm. That is, remove all but last 2 bits of each color component. Then multiply (or bit shift) the color component by 85. [source: Wikipedia]

You also need to complete the main program to handle -r flags $./lab5 -c file1 file2 // tree is converted to a cat really cool!! Style Points Proper use of functions (passing/returning arguments etc), commenting, style, handin, compile, indenting, and efficiency of the solution are worth an additional 10 points. Algorithms for Part 2: You need to use a non-trivial algorithm to decrypt the bytes of the file. A trivial algorithm is one that negates each bit of the image. The decryption algorithm then will negate the bits again to get the original image back. Here is what happens to Prof. Guna when we applied that algorithm to his image. Here is a series of other encryption algorithms by manipulating the color depth of the original image. Be creative and come up with an encryption algorithm that does something really cool (like complete distortion). Ideally, after you apply your encryption algorithm, we should not be to tell what the original image was but has a shadow of the image. Shifting the bit patterns to encrypt may not be a good idea. Be careful! You encryption algorithm cannot afford to lose any bits! Masking is a good way to turn off some bits and then unmasking can recover those bits. We will discuss masking techniques in class. Here are some more examples of encrypted images using a simple mask:

More examples Running the program: Use the Makefile to test your program. Your program should run by typing files names and command line options as follows. $./lab5 e file1 file2 //encrypt file1 and write to file2 $./lab5 -d file2 file1 // decrypt file2 and write to file1 $./lab5 -r file1 file2 // rotate file1 and write to file2 $./lab5 -c file1 file2 // apply cool algorithm Extra Credit: There is some opportunity to get extra credit in this assignment. TA s will consider giving up to +5 points for really cool algorithms. You should write why it is a really cool algorithm in a readme.txt file in the handin folder. For more advanced users, you can also think of how to implement an edge detection algorithm. Edges can be detected, in theory, by observing changes in depth of color intensity, variations in scene illumination, change in material properties etc. Your algorithm can generalize to images say, passport images of people, so you can mark the outline. If you are completing this part, give a link to an image folder you tested with so TA s can try things out. Mark the outline with a red pixels. Commenting your code: Please comment your code to show what you are doing. The least amount of comments is a short description at the beginning of each function that explains what it does, what parameters it takes, and what the expected output or return value is. Downloading your code: You can download code from /afs/andrew.cmu.edu/course/15/123/downloads/lab5 All updates will be available from FAQ.txt from the Bb Submitting your code: submit main.c to /afs/andrew/course/15/123/handin/lab5/yourid. DO NOT submit any image files you are using to test the program.