You are on page 1of 72

PROJECT REPORT ON

IMAGE STEGANOGRAPHY

SUBMITTED FOR THE PARTIAL FULFILLMENT OF THE DEGREE OF BACHELOR IN ENGINEERING IN COMPUTER SCIENCE ENGINEERING

UNIVERSITY INSTITUTE OF ENGINEERING AND TECHNOLOGY PANJAB UNIVERSITY, CHANDIGARH

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, PANJAB UNIVERSITY, CHANDIGARH

CERTIFICATE

This is to certify that the following students of CSE (7th sem) have completed the work on project entitled IMAGE STEGANOGRAPHY

In partial fulfillment of the requirement for the degree of BACHELOR OF ENGINEERING to University Institute Of Engineering And Technology, Panjab University. This is record of work carried under the guidance and supervision of the undersigned.

Project Guide

University Institute of Engineering and Technology, Panjab University (Chandigarh)

The External Viva-Voice has been taken and the project report has been found to be satisfactory.

External Examiner

ACKNOWLEDGEMENT

We would like to express our deep-felt gratitude to our Project Guide, xxx for giving us an opportunity to work and for her advice, encouragement, and constant support. We wish to thank her for extending us the greatest freedom in deciding the direction and scope of our project. It has been both a privilege and a rewarding experience working with her. We would also like to thank our colleagues here at UIET for all the wonderful times we have had with them. Their valuable comments and suggestions have been vital to the completion of this work. We want to thank the faculty of UIET and the staff for providing us the means to complete our degree. And finally, we are grateful to our parents and siblings for their love, understanding, encouragement and support.

TABLE OF CONTENTS

ABSTRACT......... 1) INTRODUCTION
1.1) INTRODUCTION........... 1.2) STEGANOGRAPHY vs. CRYPTOGRAPHY...... 1.3) HISTORY OF STEGANOGRAPHY.... 1.4) STEGANOGRAPHY TYPES..... 1.5) IMAGE AND TRANSFORM DOMAIN... 1.5.1) Image Domain. 1.5.2) Transform Domain... 1.5.3) Image or Transform domain..... 1.6) ALGORITHM REQUIREMENTS..... 1.6.1) EVALUATION OF DIFFERENT TECHNIQUES ACCORDING TO TABLE-2..... 1.7) IMAGE STEGANOGRAPHY TECHNIQUES.. 1.7.1) Least significant bit insertion....... 1.7.2) Masking and filtering....... 1.7.3) Redundant Pattern Encoding.... 1.7.4) Encrypt and Scatter.. 1.7.5) Algorithms and transformations... 1.8) DETECTION TECHNIQUE FOR IMAGE STEGANOGRAPHY... 1.9) IMPLEMENTATION..... 1.10) STEGANOGRAPHY APPLICATIONS......

2) PROJECT OVERVIEW
2.1) PROJECT DESCRIPTION..... 2.2) REQUIREMENTS SPECIFICATION........................................................................................................

2.2.1) Hardware Requirements.............................................................................................. 2.2.2) Software Requirements................................................................................................

2.2.2.1) C#.NET/C++...... 2.2.2.2) Microsoft Visual Studio 2010... 2.2.2.3) Adobe Photoshop CS5.....
2.3) FEASIBILITY STUDY.............................................................................................................................. 2.4) OBJECTIVE.. ..... 2.5) SCOPE......... 2.6) IMAGE DEFINITION....... . 2.7) IMAGE COMPRESSION....... 2.8) LEAST SIGNIFICANT BIT... 2.9) DETECTION/ ATTACKS...... 2.10) BENEFITS/ DRAWBACKS.........

3) PROJECT DESIGN
3.1) WBS Diagram....... 3.2) User Interface design.......... 3.3) Encryption And Decryption Flowchart.. 4) PROJECT IMPLEMENTATION 4.1) Coding............. 4.2) Snapshots........ 4.3) Testing...................

5) PROJECT AND FUTURE SCOPE


5.1) Project Scope...... 5.2) Future Scope.......

6) CONCLUSION BIBLIOGRAPHY... APPENDIX (PROGRAM CODE).....

ABSTRACT
In todays world the art of sending & displaying the hidden information especially in public places, has received more attention and faced many challenges. Therefore, different methods have been proposed so far for hiding information in different cover media. It is well known that encryption provides secure channels for communicating entities. However, due to lack of covertness on these channels, an eavesdropper can identify encrypted streams through statistical tests and capture them for further cryptanalysis. Information hiding is an emerging research area, which encompasses applications such as copyright protection for digital media, watermarking, fingerprinting, and steganography. In watermarking applications, the message contains information such as owner identification and a digital time stamp, which usually applied for copyright protection. Fingerprint, the owner of the data set embeds a serial number that uniquely identifies the user of the data set. This adds to copyright information to makes it possible to trace any unauthorized used of the data set back to the user. Steganography hide the secrete message within the host data set and presence imperceptible and is to be reliably communicated to a receiver. The host data set is purposely corrupted, but in a covert way, designed to be invisible to an information analysis.

CHAPTER 1 INTRODUCTION

1.1) INTRODUCTION

One of the reasons that intruders can be successful is that most of the information they acquire from a system is in a form that they can read and comprehend. Intruders may reveal the information to others, modify it to misrepresent an individual or organization, or use it to launch an attack. One solution to this problem is, through the use of steganography. Steganography is a technique of hiding information in digital media. In contrast to cryptography, it is not to keep others from knowing the hidden information but it is to keep others from thinking that the information even exists. Steganography is the art of hiding the fact that communication is taking place, by hiding information in other information. Many different carrier file formats can be used, but digital images are the most popular because of their frequency on the Internet. For hiding secret information in images, there exists a large variety of steganographic techniques some are more complex than others and all of them have respective strong and weak points. Different applications have different requirements of the steganography technique used. For example, some applications may require absolute invisibility of the secret information, while others require a larger secret message to be hidden. This project intends to give an overview of image steganography, its uses and techniques. It also attempts to identify the requirements of a good steganographic algorithm and briefly reflects on which steganographic techniques are more suitable for which applications. Although, Steganography is not to be confused with Encryption, which is the process of making a message unintelligibleSteganography attempts to hide the existence of communication. The basic structure of Steganography is made up of three components: the carrier, the message, and the key. Carrier is also known as cover-object, in which the message is embedded and serves to hide the presence of the message. The carrier can be a painting, a digital image, an mp3, even a TCP/IP packet among other things. It is the object that will carry the hidden message. A key is used to decode/decipher/discover the hidden message. This can be anything from a password, a pattern, a black-light, or even lemon juice. In this project we will focus on the use of Steganography within digital images (BMP) using LSB Substitution, although the properties of Image Steganography may be substituted with audio mp3s, zip archives, and any other digital document format relatively easily.

Basically, the model for steganography is shown in Figure 1. Message is the data that the sender wishes to remain it confidential. It can be plain text, ciphertext, other image, or anything that can be embedded in a bit stream such as a copyright mark, a covert communication, or a serial number. Password is known as stego-key, which ensures that only recipient who knows the corresponding decoding key will be able to extract the message from a cover-object. The cover-object with the secretly embedded message is then called the stego-object.

Recovering message from a stego-object requires the cover-object itself and a corresponding decoding key if a stego-key was used during the encoding process. The original image may or may not be required in most applications to extract the message.

There are several suitable carriers below to be the cover-object:: 1. Network Protocols such as TCP, IP and UDP 2. Audio that using digital audio formats such as wav, midi, avi, mpeg, mpi and voc 3. File and Disk that can hides and append files by using the slack space 4. Text such as null characters, just alike morse code including html and java 5. Images file such as bmp, gif and jpg, where they can be both color and gray-scale. In general, the information hiding process extracts redundant bits from cover-object. The process consists of two steps: Identification of redundant bits in a cover-object. Redundant bits are those bits that can be modified without corrupting the quality or destroying the integrity of the cover object. The embedding process then selects the subset of the redundant bits to be replaced with data from a secret message. The stego-object is created by replacing the selected redundant bits with message bits.

1.2) STEGANOGRAPHY vs. CRYPTOGRAPHY Basically, the purpose of cryptography and steganography is to provide secret communication. However, steganography is not the same as cryptography. Cryptography hides the contents of a secret message from a malicious people, whereas steganography even conceals the existence of the message. Steganography must not be confused with cryptography, where we transform the message so as to make its meaning obscure to malicious people who intercept it. Therefore, the definition of breaking the system is different. In cryptography, the system is broken when the attacker can read the secret message. Breaking a steganographic system need the attacker to detect that steganography has been used and he is able to read the embedded message. In cryptography, the structure of a message is scrambled to make it meaningless and unintelligible unless the decryption key is available. It makes no attempt to disguise or hide the encoded message. Basically, cryptography offers the ability of transmitting information between persons in a way that prevents a third party from reading it. Cryptography can also provide authentication for verifying the identity of someone or something. In contras, steganography does not alter the structure of the secret message, but hides it inside a cover-image so it cannot be seen. A message in cipher text, for instance, might arouse suspicion on the part of the recipient while an invisible message created with steganographic methods will not. In other word, steganography prevents an unintended recipient from suspecting that the data exists. In addition, the security of classical steganography system relies on secrecy of the data encoding system. Once the encoding system is known, the steganography system is defeated. It is possible to combine the techniques by encrypting message using cryptography and then hiding the encrypted message using steganography. The resulting stego-image can be transmitted without revealing that secret information is being exchanged. Furthermore, even if an attacker were to defeat the steganographic technique and detect the message from the stego-object, he would still require the cryptographic decoding key to decipher the encrypted message. Table 1 shows that both technologies have counter advantages and disadvantages.

1.3)

HISTORY OF STEGANOGRAPHY

The word Steganography technically means covered or hidden writing. Its ancient origins can be traced back to 440 BC. Although the term steganography was only coined at the end of the 15th century, the use of steganography dates back several millennia. Some examples of use of Steganography is past times are: 1. In ancient Greece, messages were hidden on the back of wax writing tables where someone would peel off the wax that was or written on the stomachs of rabbits. 2. In Ancient Greece they used to select messengers and shave their head, they would then write a message on their head. Once the message had been written the hair was allowed to grow back. After the hair grew back the messenger was sent to deliver the message, the recipient would shave off the messengers hair to see the secrete message. 3. During World War 2 invisible ink was used to write information on pieces of paper so that the paper appeared to the average person as just being blank pieces of paper. Liquids such as milk, vinegar and fruit juices were used, because when each one of these substances were heated they darken and become visible to the human eye. Invisible ink has been in use for centuriesfor fun by children and students and for serious espionage by spies and terrorists. 4. Cryptography became very common place in the middle ages. Secret writing was employed by the Catholic Church in its various struggles down the ages and by the major governments of the time. Steganography was normally used in conjunction with cryptography to further hide secret information.

1.4) STEGANOGRAPHY TYPES

The majority of todays steganographic systems uses multimedia objects like image, audio, video etc as cover media because people often transmit digital pictures over email and other Internet communication. In modern approach, depending on the nature of cover object, steganography can be divided into five types: Text Steganography Image Steganography Audio Steganography Video Steganography Protocol Steganography So, in the modern age so many steganographic techniques have been designed which work with the above concerned objects. More often in todays security advancement, we sometimes come across a combination of Cryptography and Steganography to achieve data privacy over secrecy. Various software tools are also available in this regard.

1.5)

IMAGE AND TRANSFORM DOMAIN

Image steganography techniques can be divided into two groups: those in the Image Domain and those in the Transform Domain. Image also known as spatial domain techniques embed messages in the intensity of the pixels directly, while for transform also known as frequency domain, images are first transformed and then the message is embedded in the image. Image domain techniques encompass bit-wise methods that apply bit insertion and noise manipulation and are sometimes characterised as simple systems. The image formats that are most suitable for image domain steganography are lossless and the techniques are typically dependent on the image format. Steganography in the transform domain involves the manipulation of algorithms and image transforms. These methods hide messages in more significant areas of the cover image, making it more robust. Many transform domain methods are independent of the image format and the embedded message may survive conversion between lossy and lossless compression. In the next sections steganographic algorithms will be explained in categories according to image file formats and the domain in which they are performed. 1.5.1) Image Domain Least Significant Bit Least significant bit (LSB) insertion is a common, simple approach to embedding information in a cover image. The least significant bit (in other words, the 8th bit) of some or all of the bytes inside an image is changed to a bit of the secret message. When using a 24-bit image, a bit of each of the red, green and blue color components can be used, since they are each represented by a byte. (It has been explained in detail later). LSB and Palette Based Images Palette based images, for example GIF images, are another popular image file format commonly used on the Internet. By definition a GIF image cannot have a bit depth greater than 8, thus the maximum number of colors that a GIF can store is 256. GIF images are indexed images where the colors used in the image are stored in a palette, sometimes referred to as a color lookup table. Each pixel is represented as a single byte and the pixel data is an index to the color palette. The colors of the palette are typically ordered from the most used color to the least used colors to reduce lookup time.

GIF images can also be used for LSB steganography, although extra care should be taken. The problem with the palette approach used with GIF images is that should one change the least significant bit of a pixel, it can result in a completely different color since the index to the color palette is changed. If adjacent palette entries are similar, there might be little or no noticeable change, but should the adjacent palette entries be very dissimilar, the change would be evident. One possible solution is to sort the palette so that the color differences between consecutive colors are minimized. Another solution is to add new colors which are visually similar to the existing colors in the palette. This requires the original image to have less unique colors than the maximum number of colors (this value depends on the bit depth used). Using this approach, one should thus carefully choose the right cover image. Unfortunately any tampering with the palette of an indexed image leaves a very clear signature, making it easier to detect. A final solution to the problem is to use greyscale images. In an 8-bit greyscale GIF image, there are 256 different shades of grey. The changes between the colors are very gradual, making it harder to detect. 1.5.2) Transform Domain To understand the steganography algorithms that can be used when embedding data in the transform domain, one must first explain the type of file format connected with this domain. The JPEG file format is the most popular image file format on the Internet, because of the small size of the images. JPEG compression To compress an image into JPEG format, the RGB color representation is first converted to a YUV representation. In this representation the Y component corresponds to the luminance (or brightness) and the U and V components stand for chrominance (or color).

According to research the human eye is more sensitive to changes in the brightness (luminance) of a pixel than to changes in its color. This fact is exploited by the JPEG

compression by down-sampling the color data to reduce the size of the file. The color components (U and V) are halved in horizontal and vertical directions, thus decreasing the file size by a factor of 2. The next step is the actual transformation of the image. For JPEG, the Discrete Cosine Transform (DCT) is used, but similar transforms are for example the Discrete Fourier Transform (DFT). These mathematical transforms convert the pixels in such a way as to give the effect of spreading the location of the pixel values over part of the image. The DCT transforms a signal from an image representation into a frequency representation, by grouping the pixels into 8 8 pixel blocks and transforming the pixel blocks into 64 DCT coefficients each. A modification of a single DCT coefficient will affect all 64 image pixels in that block. The next step is the quantization phase of the compression. Here another biological property of the human eye is exploited: The human eye is fairly good at spotting small differences in brightness over a relatively large area, but not so good as to distinguish between different strengths in high frequency brightness. This means that the strength of higher frequencies can be diminished, without changing the appearance of the image. JPEG does this by dividing all the values in a block by a quantization coefficient. The results are rounded to integer values and the coefficients are encoded using Huffman coding to further reduce the size. JPEG steganography Originally it was thought that steganography would not be possible to use with JPEG images, since they use lossy compression which results in parts of the image data being altered. One of the major characteristics of steganography is the fact that information is hidden in the redundant bits of an object and since redundant bits are left out when using JPEG it was feared that the hidden message would be destroyed. Even if one could somehow keep the message intact it would be difficult to embed the message without the changes being noticeable because of the harsh compression applied. However, properties of the compression algorithm have been exploited in order to develop a steganographic algorithm for JPEGs. One of these properties of JPEG is exploited to make the changes to the image invisible to the human eye. During the DCT transformation phase of the compression algorithm, rounding errors occur in the coefficient data that are not noticeable. Although this property is what classifies the

algorithm as being lossy, this property can also be used to hide messages. It is neither feasible nor possible to embed information in an image that uses lossy compression, since the compression would destroy all information in the process. Thus it is important to recognize that the JPEG compression algorithm is actually divided into lossy and lossless stages. The DCT and the quantization phase form part of the lossy stage, while the Huffman encoding used to further compress the data is lossless. Steganography can take place between these two stages. Using the same principles of LSB insertion the message can be embedded into the least significant bits of the coefficients before applying the Huffman encoding. By embedding the information at this stage, in the transform domain, it is extremely difficult to detect, since it is not in the visual domain. 1.5.3) Image or Transform domain As seen in the diagram above, some steganographic algorithms can either be categorized as being in the image domain or in the transform domain depending on the implementation. Patchwork Patchwork is a statistical technique that uses redundant pattern encoding to embed a message in an image. The algorithm adds redundancy to the hidden information and then scatters it throughout the image. A Pseudo random generator is used to select two areas of the image (or patches), patch A and patch B. All the pixels in patch A is lightened while the pixels in patch B are darkened. In other words the intensities of the pixels in the one patch are increased by a constant value, while the pixels of the other patch are decreased with the same constant value. The contrast changes in this patch subset encodes one bit and the changes are typically small and imperceptible, while not changing the average luminosity. A disadvantage of the patchwork approach is that only one bit is embedded. One can embed more bits by first dividing the image into sub-images and applying the embedding to each of them. The advantage of using this technique is that the secret message is distributed over the entire image, so should one patch be destroyed, the others may still survive. This however, depends on the message size, since the message can only be repeated throughout the image if it is small enough. If the message is too big, it can only be embedded once. The patchwork approach is used independent of the host image and proves

to be quite robust as the hidden message can survive conversion between lossy and lossless compression. Spread Spectrum In spread spectrum techniques, hidden data is spread throughout the cover-image making it harder to detect. A system proposed by Marvel et al. combines spread spectrum communication, error control coding and image processing to hide information in images. Spread spectrum communication can be defined as the process of spreading the bandwidth of a narrowband signal across a wide band of frequencies. This can be accomplished by adjusting the narrowband waveform with a wideband waveform, such as white noise. After spreading, the energy of the narrowband signal in any one frequency band is low and therefore difficult to detect. In spread spectrum image steganography the message is embedded in noise and then combined with the cover image to produce the stego-image. Since the power of the embedded signal is much lower than the power of the cover image, the embedded image is not perceptible to the human eye or by computer analysis without access to the original image.

1.6) ALGORITHM REQUIREMENTS

All steganographic algorithms have to comply with a few basic requirements. The most important requirement is that a steganographic algorithm has to be imperceptible. These requirements are as follows: 1. Invisibility The invisibility of a steganographic algorithm is the first and foremost requirement, since the strength of steganography lies in its ability to be unnoticed by the human eye. The moment that one can see that an image has been tampered with, the algorithm is compromised. 2. Payload capacity Unlike watermarking, which needs to embed only a small amount of copyright information, steganography in other hand requires sufficient embedding capacity. 3. Robustness against statistical attacks Statistical steganalysis is the practice of detecting hidden information through applying statistical tests on image data. Many steganographic algorithms leave a signature when embedding information that can be easily detected through statistical analysis. To be able to pass by a warden without being detected, a steganographic algorithm must not leave such a mark in the image as be statistically significant. 4. Robustness against image manipulation In the communication of a stego-image by trusted systems, the image may undergo changes by an active warden in an attempt to remove hidden information. Image manipulation, such as cropping or rotating, can be performed on the image before it reaches its destination. Depending on the manner in which the message is embedded, these manipulations may destroy the hidden message. It is preferable for steganographic algorithms to be robust against either malicious or unintentional changes to the image. 5. Independent of file format With many different image file formats used on the Internet, it might seem suspicious that only one type of file format is continuously communicated between two parties. The most powerful steganographic algorithms thus possess the ability to embed information in any type of file. This also solves the problem of not always being able to find a suitable image at the right moment, in the right format to use as a cover image. 6. Unsuspicious files This requirement includes all characteristics of a steganographic algorithm that may result in images that are not used normally and may cause

suspicion. Abnormal file size, for example, is one property of an image that can result in further investigation of the image by a warden.

The levels at which the algorithms satisfy the requirements are defined as high, medium and low. A high level means that the algorithm completely satisfies the requirement, while a low level indicates that the algorithm has a weakness in this requirement. A medium level indicates that the requirement depends on outside influences, for example the cover image used. LSB in GIF images has the potential of hiding a large message, but only when the most suitable cover image has been chosen. The ideal, in other words a perfect steganographic algorithm would have a high level in every requirement. Unfortunately its hard to develop an algorithm that satisfies all of the requirements. Thus a trade-off will exist in most cases, depending on which requirements are more important for the specific application.

1.6.1) EVALUATION OF DIFFERENT TECHNIQUES ACCORDING TO TABLE-2 LSB in BMP When embedding a message in a raw image, which has not been changed with compression, such as a BMP, there exists a trade-off between the

invisibility of the message and the amount of information that can be embedded. A BMP is capable of hiding quite a large message, but the fact that more bits are altered results in a larger possibility that the altered bits can be seen with the human eye. The main disadvantage regarding LSB in BMP images is surely the suspicion that might arise from a very large BMP image being transmitted between parties, since BMP is not widely used anymore. Suggested applications: LSB in BMP is most suitable for applications where the focus is on the amount of information to be transmitted and not on the secrecy of that information. LSB in GIF The strong and weak points regarding embedding information in GIF images using LSB are more or less the same as those of using LSB with BMP. The main difference is that since GIF images only have a bit depth of 8, the amount of information that can be hidden is less than with BMP. GIF images are especially vulnerable to statistical or visual attacks since the palette processing that has to be done leaves a very definite signature on the image. This approach is dependent on the file format as well as the image itself, since a wrong choice of image can result in the message being visible. Suggested applications: LSB in GIF is a very efficient algorithm to use when embedding a reasonable amount of data in a greyscale image. JPEG compression The process of embedding information during JPEG compression results in a stego image with a high level of invisibility, since the embedding takes place in the transform domain. JPEG is the most popular image file format on the Internet and the image sizes are small because of the compression, thus making it the least suspicious algorithm to use. However, the process of the compression is a very mathematical process, making it more difficult to implement. Suggested applications: The JPEG file format can be used for most applications of steganography, but is especially suitable for images that have to be communicated over an open systems environment like the Internet. Patchwork The biggest disadvantage of the patchwork approach is the small amount of information that can be hidden in one image. This property can be changed to accommodate more information but one may have to sacrifice the

secrecy of the information. Patchworks main advantage, however, is its robustness against malicious or unintentional image manipulation. Should a stego image using patchwork be cropped or rotated, some of the message data may be lost but since the message is repeatedly embedded in the image, most of the information will survive. Suggested applications: Patchwork is most suitable for transmitting a small amount of very sensitive information. Spread spectrum Spread spectrum techniques satisfies most requirements and is especially robust against statistical attacks, since the hidden information is scattered throughout the image, while not changing the statistical properties. Suggested applications: Spread spectrum techniques can be used for most steganography applications, although its highly mathematical and intricate approach may prove too much for some.

1.7) IMAGE STEGANOGRAPHY TECHNIQUES To hide information, straight message insertion may encode every bit of information in the image or selectively embed the message in noisy areas that draw less attention- those areas where there is a great deal of natural color variation. The message may also be scattered randomly throughout the image. A number of ways exist to hide information in digital media. Common techniques which with varying degrees of success include:

1. Least significant bit insertion 2. Masking and filtering 3. Redundant Pattern Encoding 4. Encrypt and Scatter 5. Algorithms and transformations 1.7.1) Least significant bit insertion
Least significant bits (LSB) insertion is a simple approach to embedding information in image file. The simplest steganographic techniques embed the bits of the message directly into least significant bit plane of the cover-image in a deterministic sequence. Modulating the least significant bit does not result in human-perceptible difference because the amplitude of the change is small. In this method the LSB of a byte is replaced with an Ms bit. This

technique works well for image, audio and video steganography. To the human eye, the resulting image will look identical to the cover object. 1.7.2) Masking and filtering
Masking and filtering techniques, usually restricted to 24 bits and gray scale images, hide information by marking an image, in a manner similar to paper watermarks. The techniques performs analysis of the image, thus embed the information in significant areas so that the hidden message is more integral to the cover image than just hiding it in the noise level. They

hide info in a way similar to watermarks on actual paper and are sometimes used as digital watermarks. Masking images entails changing the luminance of the masked area. The smaller the luminance change, the less of a chance that it can be detected. Masking is more robust than LSB insertion with respect to compression, cropping, and some image processing. Masking techniques embed information in significant areas so that the hidden message is more integral to the cover image than just hiding it in the noise level. This makes it more suitable than LSB with, for instance, lossy JPEG images. 1.7.3) Redundant Pattern Encoding Patchwork and other similar tools do redundant pattern encoding, which is a sort of spread spectrum technique. It works by scattering the message throughout the picture. This makes the image more resistant to cropping and rotation. Smaller secret images work better to

increase the redundancy embedded in the cover image, and thus make it easier to recover if the stego-image is manipulated. 1.7.4) Encrypt and Scatter The Encrypt and Scatter technique tries to emulate white noise. It is mostly used in image steganography. White Noise Storm is one such program that employs spread spectrum and frequency hopping. It does this by scattering the message throughout an image on eight channels within a random number that is generated by the previous window size and data channel. The channels then swap rotate, and interlace amongst each other. Each channel represents one bit and as a result there are many unaffected bits in each channel. This technique is a lot harder to extract a message out of than an LSB scheme because to decode you must first detect that a hidden image exists and extract the bit pattern from the file. While that is true for any stego-image you will also need the algorithm and stego key to decode the bit pattern, both of which are not required to recover a message from LSB. Some people prefer this method due to the considerable amount of extra effort that someone without the algorithm and stego-key would have to go through to extract the message. Even though White Noise Storm provides extra security against message extraction it is just as susceptible as straight LSB to image degradation due to image processing. 1.7.5) Algorithms and transformations
Transform techniques embed the message by modulating coefficients in a transform domain, such as the Discrete Cosine Transform (DCT) used in JPEG compression, Discrete Fourier Transform, or Wavelet Transform. These methods hide messages in significant areas of the cover-image, which make them more robust to attack. Transformations can be applied over the entire image, to block through out the image, or other variants. LSB modification technique

for images does hold good if any kind of compression is done on the resultant stego-image e.g. JPEG, GIF etc. JPEG images use the discrete cosine transform to achieve compression. DCT is a lossy compression transform because the cosine values cannot be calculated exactly, and repeated calculations using limited precision numbers introduce rounding errors into the final result. Variances between original data values and restored data values depend on the method used to calculate DCT.

1.8) DETECTION TECHNIQUE FOR IMAGE STEGANOGRAPHY Even though stego-images can rarely be spotted by the naked eye, they usually leave behind some type of fingerprint or statistical hint that they have been modified. It is those discrepancies which an analysis tool may be able to detect. Since some techniques and their effects are commonly known, a statistical analysis of an image can be performed to check for a hidden message(s) in it.

A widely used technique for image scanning involves statistical analysis. Most steganographic algorithms that work on images, assume that the least significant bit is more or less random. This is however, an incorrect assumption. While the LSB might not seem to be of much importance, applying a filter which only shows the least significant bits, will still produce a recognizable image. Since this is the case, it can be concluded that the LSB are not random at all, but actually contain information about the whole image. When inserting a hidden message into an image, this property changes. Especially with encrypted data, which has very high entropy, the LSB of the cover image will no longer contain information about the original, but because of the modifications they will now be more or less random. With a statistical analysis on the LSB, the difference between random values and real image values can easily be detected. Using this technique, it is also possible to detect messages hidden inside JPEG files with the DCT method, since this also involves LSB modifications, even though these take place in the frequency domain.

1.9) IMPLEMENTATION There are currently three effective methods in applying Image Steganography in spatial domain: LSB Substitution Blocking (DCT) Palette Modification.

LSB (Least Significant Bit) Substitution is the process of modifying the least significant bit of the pixels of the carrier image. Blocking works by breaking up an image into blocks and using Discrete Cosine Transforms (DCT). Each block is broken into 64 DCT coefficients that approximate luminance and colorthe values of which are modified for hiding messages. Palette Modification replaces the unused colors within an images color palette with colors that represent the hidden message. 1.10) STEGANOGRAPHY APPLICATIONS Image Steganography has many applications, especially in todays modern, high-tech world. Steganography can be used anytime you want to hide data. There are many reasons to hide data but they all boil down to the desire to prevent unauthorized persons from becoming aware of the existence of a message. In the business world steganography can be used to hide a secret chemical formula or plans for a new invention. Steganography can also be used for corporate espionage by sending out trade secrets without anyone at the company being any the wiser. Steganography can also be used in the noncommercial sector to hide information that someone wants to keep private. Privacy and anonymity is a concern for most people on the internet. Image Steganography allows for two parties to communicate secretly and covertly. It allows for some morallyconscious people to safely whistle blow on internal actions; it allows for copyright protection on digital files using the message as a digital watermark. One of the other main uses for Image Steganography is for the transportation of high-level or top-secret documents between international governments. While Image Steganography has many legitimate uses, it can also be quite nefarious. It can be used by hackers to send viruses and trojans to compromise machines, and also by terrorists and other organizations that rely on covert operations to communicate secretly and safely. Spies have used it since the time of the Greeks to pass messages undetected. Terrorists can also use steganography to keep their communications secret and to coordinate attacks. It is exactly this potential that we will investigate in the next section. Because you can hide information without the cover source changing, steganography can also be used to implement watermarking. Although the concept of watermarking is not necessarily

steganography, there are several steganographic techniques that are being used to store watermarks in data. The main difference is on intent, while the purpose of steganography is hiding information, watermarking is merely extending the cover source with extra information. Since people will not accept noticeable changes in images, audio or video files because of a watermark, steganographic methods can be used to hide this. In feature tagging, captions, annotations, time stamps, and other descriptive elements can be embedded inside an image. Copying the stegoimage also copies of the embedded features and only parties who posses the decoding stego-key will be able to extract and view the features. On the other hand, secret communication does not advertise a covert communication by using steganography. Therefore, it can avoid scrutiny of the sender, message and recipient. This is effective only if the hidden communication is not detected by the others people.

CHAPTER 2 PROJECT OVERVIEW

2.1) PROJECT DESCRIPTION There are two trends at the time to implement steganographic algorithms: the methods that work in the spatial domain (altering the desired characteristics on the file itself) and the methods that work in the transform domain (performing a series of changes to the cover image before hiding information. To select the best areas the Discrete Cosine Transform DCT, Wavelet Transform, etc. are used). While the algorithms that work in the transform domain are more robust, that is, more resistant to attacks, the algorithms that work in the spatial domain are simpler and faster.

The best known steganographic method that works in the spatial domain is the LSB (Least Significant Bit), which replaces the least significant bits of pixels selected to hide the information. This method has several implementation versions that improve the algorithm in certain aspects. We have chosen to implement LSB Substitution in our project because of its ubiquity among carrier formats and message types. With LSB Substitution, we could easily change from Image Steganography to Audio Steganography and hide a zip archive instead of a text message. LSB Substitution lends itself to become a very powerful Steganographic method with few limitations. LSB Substitution works by iterating through the pixels of an image and extracting the ARGB values. It then separates the color channels and gets the least significant bit. Meanwhile, it also iterates through the characters of the message setting the bit to its corresponding binary value. In our project, we have made an APPLICATION on steganography to be used by the Indian Defence Services in which we provide a user friendly interface to encrypt a data file in a bmp image format. We have used a variation of LSB technique where we are encoding the last 4 LSBs in direct proportion to the first 4 MSBs, by which I mean that, if in out image, the 8 bits are: 11110101, and we need to encode 1101 in our image bits, we will encode all the last four bits and the output will be, 11111101. Similarly, if the first four bits of our image are 11100110, we will encode the last 3 bits and so on

The cover-image will be combined with the message. This will produce the output called stego-image. Figure 2 is illustrating the process. The Stego-image seems identical to the cover-image. However, there are hidden message that imperceptible. This process simply embedded the message into the cover-image without supplied any password or stego-key. At this stage, we decided to do so because we have to understand the ways of LSB insert the message bit into the image and extract the message from the stego-image produced.

2.2) REQUIREMENT SPECIFICATION 2.2.1) Hardware Requirements: Minimum 1GB RAM, Minimum 10 GB Hard Disk Space Operating System supported: Windows XP, Windows Vista, Windows 7 2.2.2) Software Requirements: Visual Studio 2010, .NET Framework 4.0 and Adobe Photoshop CS5 installed on the system. SOFTWARE DESCRIPTION 2.2.2.1) C#.NET/ C++ C# is a relatively new language that was unveiled to the world when Microsoft announced the first version of its .NET Framework in July 2000. Since then its popularity has rocketed, and it has arguably become the language of choice for both Windows and Web developers who use the .NET Framework. Part of the appeal of C# comes from its clear syntax, which derives from C/C++ but simplifies some things that have previously discouraged some programmers. Despite this simplification, C# has retained the power of C++, and there is now no reason not to move into C#. The language is not difficult and its a great one to learn elementary programming techniques with.
.

C#.NET a window application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites, web applications and web services is used for our projects software coding. By design, C# is the programming language that most directly reflects the underlying Common Language Infrastructure (CLI). Most of its intrinsic types correspond to valuetypes implemented by the CLI framework. However, the language specification does not state the code generation requirements of the compiler: that is, it does not state that a C#

compiler must target a Common Language Runtime, or generate Common Intermediate Language (CIL), or generate any other specific format. Theoretically, a C# compiler could generate machine code like traditional compilers of C++ or Fortran. Some notable distinguishing features of C# are: There are no global variables or functions. All methods and members must be declared within classes. Static members of public classes can substitute for global variables and functions. Local variables cannot shadow variables of the enclosing block, unlike C and C++. Variable shadowing is often considered confusing by C++ texts. C# supports a strict Boolean datatype, bool. Statements that take conditions, such as while and if, require an expression of a type that implements the true operator, such as the boolean type. While C++ also has a boolean type, it can be freely converted to and from integers, and expressions such as if(a) require only that a is convertible to bool, allowing a to be an int, or a pointer. C# disallows this "integer meaning true or false" approach on the grounds that forcing programmers to use expressions that return exactly bool can prevent certain types of common programming mistakes in C or C++ such as if (a = b) (use of assignment = instead of equality ==). In C#, memory address pointers can only be used within blocks specifically marked as unsafe, and programs with unsafe code need appropriate permissions to run. Most object access is done through safe object references, which always either point to a "live" object or have the well-defined null value; it is impossible to obtain a reference to a "dead" object (one which has been garbage collected), or to a random block of memory. An unsafe pointer can point to an instance of a valuetype, array, string, or a block of memory allocated on a stack. Code that is not marked as unsafe can still store and manipulate pointers through the System.IntPtr type, but it cannot dereference them. Managed memory cannot be explicitly freed; instead, it is automatically garbage collected. Garbage collection addresses the problem of memory leaks by freeing the programmer of responsibility for releasing memory which is no longer needed.

In addition to the try...catch construct to handle exceptions, C# has a try...finally construct to guarantee execution of the code in the finally block.

Multiple inheritance is not supported, although a class can implement any number of interfaces. This was a design decision by the language's lead architect to avoid complication and simplify architectural requirements throughout CLI.

C# is more type safe than C++. The only implicit conversions by default are those which are considered safe, such as widening of integers. This is enforced at compile-time, during JIT, and, in some cases, at runtime. There are no implicit conversions between booleans and integers, nor between enumeration members and integers (except for literal 0, which can be implicitly converted to any enumerated type). Any user-defined conversion must be explicitly marked as explicit or implicit, unlike C++ copy constructors and conversion operators, which are both implicit by default.

Enumeration members are placed in their own scope. C# provides properties as syntactic sugar for a common pattern in which a pair of methods, accessor (getter) and mutator (setter) encapsulate operations on a single attribute of a class.

Full type reflection and discovery is available. C# currently (as of version 4.0) has 77 reserved words. Checked exceptions are not present in C# (in contrast to Java). This has been a conscious decision based on the issues of scalability and versionability.

2.2.2.2) Microsoft Visual Studio 2010 Microsoft Visual Studio 2010 version 10.0.30319.1 RTMRel. 2010 Microsoft Corporation.

2.2.2.3) Adobe Photoshop CS5 Its the latest version of Adobe Photoshop CS5 version 12.0 x64. 1990-2010 Adobe Systems Incorporated. Its snapshot is given below:

2.3) FEASILBILITY STUDY Technical Feasibility Image Steganography is a defence application with a back-end coding done in C#.NET that allows a user to hide data (documents or text files) in an image. The user friendly interface requires no technical skills and is easy to operate on. Visual Studio 2010 using .NET 4.0 framework is used for the design and coding purposes. Adobe Photoshop CS5 has also been used to design the header of the application with an animated sequence of images. Economic Feasibility The project is economic and highly beneficial project as far as the cost of development is considered. No extra costs were incurred apart from the software used. Operational Feasibility The project is operationally very feasible as it is user-friendly, the user doesnt need any kind of knowledge about the software used in the project. The project is also really helpful as the user can use it to send encrypted data at any moment of time using the internet or the LAN system.

2.4) OBJECTIVE This project comprehends the following objectives: To produce security tool based on steganographic techniques. To explore LSB techniques of hiding data using steganography.

2.5) SCOPE The scope of the project as follows: Implementation of a variation of LSB technique for hiding information i.e. text in image files. 2.6) IMAGE DEFINITION

To a computer, an image is a collection of numbers that constitute different light intensities in different areas of the image. This numeric representation forms a grid and the individual points are referred to as pixels. Most images on the Internet consists of a rectangular map of the images pixels (represented as bits) where each pixel is located and its color. These pixels are displayed horizontally row by row. The number of bits in a color scheme, called the bit depth, refers to the number of bits used for each pixel. The smallest bit depth in current color schemes is 8, meaning that there are 8 bits used to describe the color of each pixel. Monochrome and greyscale images use 8 bits for each pixel and are able to display 256 different colors or shades of grey. Digital color images are typically stored in 24-bit files and use the RGB color model, also known as true color. All color variations for the pixels of a 24-bit image are derived from three primary colors: red, green and blue, and each primary color is represented by 8 bits. Thus in one given pixel, there can be 256 different quantities of red, green and blue, adding up to more than 16million combinations, resulting in more than 16-million colors. Not surprisingly the larger amount of colors that can be displayed, the larger the file size. For this project, we are considering 8-bit images.

2.7) IMAGE COMPRESSION

When working with larger images of greater bit depth, the images tend to become too large to transmit over a standard Internet connection. In order to display an image in a reasonable amount of time, techniques must be incorporated to reduce the images file size. These techniques make use of mathematical formulas to analyse and condense image data, resulting in smaller file sizes. This process is called compression. In images there are two types of compression: lossy and lossless. Both methods save storage space, but the procedures that they implement differ. Lossy compression creates smaller files by discarding excess image data from the original image. It removes details that are too small for the human eye to differentiate, resulting in close approximations of the original image, although not an exact duplicate. An example of an image format that uses this compression technique is JPEG (Joint Photographic Experts Group). Lossless compression, on the other hand, never removes any information from the original image, but instead represents data in mathematical formulas. The original images integrity is maintained and the decompressed image output is bit-by-bit identical to the original image input. The most popular image formats that use lossless compression is GIF (Graphical Interchange Format) and 8-bit BMP (a Microsoft Windows bitmap file). Compression plays a very important role in choosing which steganographic algorithm to use. Lossy compression techniques result in smaller image file sizes, but it increases the possibility that the embedded message may be partly lost due to the fact that excess image data will be removed. Lossless compression though, keeps the original digital image intact without the chance of lost, although is does not compress the image to such a small file size. Different steganographic algorithms have been developed for both of these compression types and will be explained in the following sections.

2.8) LEAST SIGNIFICANT BIT

Least significant bit (LSB) insertion is a common, simple approach to embedding information in a cover image. The least significant bit (in other words, the 8th bit) of some or all of the bytes inside an image is changed to a bit of the secret message. When using a 24-bit image, a bit of each of the red, green and blue color components can be used, since they are each represented by a byte. In other words, one can store 3 bits in each pixel. An 800 600 pixel image, can thus store a total amount of 1,440,000 bits or 180,000 bytes of embedded data. For example a grid for 3 pixels of a 24-bit image can be as follows: (00101101 00011100 11011100) (10100110 11000100 00001100) (11010010 10101101 01100011) When the number 200, which binary representation is 11001000, is embedded into the least significant bits of this part of the image, the resulting grid is as follows: (00101101 00011101 11011100) (10100110 11000101 00001100) (11010010 10101100 01100011) Although the number was embedded into the first 8 bytes of the grid, only the 3 underlined bits needed to be changed according to the embedded message. On average, only half of the bits in an image will need to be modified to hide a secret message using the maximum cover size. Since there are 256 possible intensities of each primary color, changing the LSB of a pixel results in small changes in the intensity of the colors. These changes cannot be perceived by the human eye - thus the message is successfully hidden. With a well-chosen image, one can even hide the message in the least as well as second to least significant bit and still not see the difference. In the above example, consecutive bytes of the image data from the first byte to the end of the message are used to embed the information. This approach is very easy to detect. A slightly more secure system is for the sender and receiver to share a secret key that specifies only certain pixels to be changed. Should an adversary suspect that LSB

steganography has been used, he has no way of knowing which pixels to target without the secret key. In its simplest form, LSB makes use of BMP images, since they use lossless compression. Unfortunately to be able to hide a secret message inside a BMP file, one would require a very large cover image. Nowadays, BMP images of 800 600 pixels are not often used on the Internet and might arouse suspicion. For this reason, LSB steganography has also been developed for use with other image file formats. 2.9) DETECTION/ ATTACKS While the purpose of Steganography is to hide messages, it may not be very effective at doing so. There are several attacks that one may execute to test for Steganographed images. They are: Visual Attacks Enhanced LSB Attacks Chi-Square Analysis, and Other statistical analyses.

In performing a visual attack you must have the original virgin image to compare it the Steganographed image and visually compare the two for artifacts. In the Enhanced LSB Attack, you process the image for the least significant bits and if the LSB is equal to one, multiply it by 255 so that it becomes its maximum value. Chi-Square Analysis calculates the average LSB and constructs a table of frequencies and Pair of Values; it takes the data from these two tables and performs a chi-square test. It measures the theoretical vs. calculated population difference. The Chi-Square Analysis calculates the chi-square for every 128 bytes of the image. As it iterates through, the chisquare value it calculates becomes more and more accurate until too large of a dataset has been produced. Because this attack relies on statistical analysis it cannot detect patterns or Steganography on very complex images with lots of noise than one can detect through visualization of the Enhanced LSBs.

2.10) BENEFITS/ DRAWBACKS

The advantages of LSB are its simplicity to embed the bits of the message directly into the LSB plane of cover-image and many techniques use these methods. Modulating the LSB does not result in a human-perceptible difference because the amplitude of the change is small. Therefore, to the human eye, the resulting stego-image will look identical to the cover-image. This allows high perceptual transparency of LSB. However, there are a few weaknesses of using LSB. It is very sensitive to any kind of filtering or manipulation of the stego-image. Scaling, rotation, cropping, addition of noise, or lossy compression to the stego-image will destroy the message. On the other hand, for the hiding capacity, the size of information to be hidden relatively depends to the size of the cover-image. The message size must be smaller than the image. A large capacity allows the use of the smaller cover-image for the message of fixed size, and thus decreases the bandwidth required to transmit the stego-image. Another weakness is an attacker can easily destruct the message by removing or zeroing the entire LSB plane with very little change in the perceptual quality of the modified stegoimage. Therefore, if this method causes someone to suspect something hidden in the stegoimage, then the method is not success.

CHAPTER 3 PROJECT DESIGN

3.1) WORK BREAKDOWN STRUCTURE

3.2) INTERFACE DESIGN

The interface is designed keeping the user in mind. There are two buttons on the left panel, with one asking the user to load the file to be encrypted, and the other asking the user to load the image in which the data is to be hidden. Only after the two files are browsed, will the encryption start, or else itll give an error message asking the user to load both the files. After the user clicks on the encryption button, the status bar at the bottom of the application gives us the state of encryption and after the encryption is complete, we get a message box stating the same. But before encryption is done, itll ask the user to give the name by which the used would like to save the encrypted image which should also necessarily be filled.

CHAPTER 4 PROJECT IMPLEMETATION

4.1) Coding: The algorithm implementation of steganography in C# on Visual Studio.

4.2) SNAPSHOTS The snapshots of the project are given below: a) Interface in the beginning:

b) Interface with the second animation sequence:

c) Interface with the third animation sequence:

d) Interface with the fourth animation sequence:

e) Browsing the bitmap image file which will serve as a carrier:

f) Browsing the (*.txt) file which is to be encrypted:

g) Naming the new encrypted file and its location:

h) After the file, image and the destination location of the encrypted file:

i) Encrypted image has been saved successfully! Message Box:

4.3) Testing: Functionality testing: testing if the end product is fully functional with all its functionality intact. Usability testing: testing if the application works fine with all its upload links and buttons working. Interface testing: testing if the interface is use friendly or not. Compatibility testing: testing its compatibility with other systems or operating systems.

CHAPTER 5 PROJECT AND FUTURE SCOPE

5.1) PROJECT SCOPE

This application would enable defence personnels to send confidential data of high priority to others. Because the human eye can not decipher that there is any encrypted text, it can be put to great use while remaining easy to understand and use.

5.2) FUTURE SCOPE In todays world, we often listen a popular term Hacking. Hacking is nothing but an unauthorized access of data which can be collected at the time of data transmission. With respect to steganography this problem is often taken as Steganalysis. Steganalysis is a process in which a steganalyzer cracks the cover object to get the hidden data. So, whatever be the technique will be developed in future, degree of security related with that has to be kept in mind. It is hoped that Dual Steganography, Steganography along with Cryptography may be some of the future solution for this above mentioned problem. We hope to add support to hide all file formats. This allows for a much broader spectrum of uses: one would be able to encode .gif, .png, .pdf, .mp3, etc. The program would be more versatile because often hiding text just isnt enough. We also would like to implement batch image processing and statistical analysis so that we can run the program through a dataset of images and detect Steganography and perhaps crawl through Google Image Search to see how prevalent Steganography is. We eventually plan to port the program to use C/C++ so that we may take advantage of bit-fields in C and learn to code GUIs as well. I have a plug-in handler developed for C++ that I would like to use in this project so that third-party developers may contribute to the project.

CHAPTER 6 CONCLUSION

6.1) CONCLUSION

As steganography becomes more widely used in computing, there are issues that need to be resolved. There are a wide variety of different techniques with their own advantages and disadvantages. Many currently used techniques are not robust enough to prevent detection and removal of embedded data. The use of benchmarking to evaluate techniques should become more common and a more standard definition of robustness is required to help overcome this. For a system to be considered robust it should have the following properties: The quality of the media should not noticeably degrade upon addition of a secret data. Secret data should be undetectable without secret knowledge, typically the key. If multiple data are present they should not interfere with each other. The secret data should survive attacks that dont degrade the perceived quality of the work. This work presents a scheme that can transmit large quantities of secret information and provide secure communication between two communication parties. Both steganography and cryptography can be woven into this scheme to make the detection more complicated. Any kind of text data can be employed as secret msg. The secret message employing the concept of steganography is sent over the network. In addition, the proposed procedure is simple and easy to implement. Also, the developed system has many practical, personal and militaristic applications for both point-to-point and point-to multi- point communications.

BIBLIOGRAPHY

BIBLIOGRAPHY

http://www.engpaper.com/free-research-papers-steganography.htm http://en.wikipedia.org/wiki/Steganography www.ece.stevens-tech.edu/~mouli/lsbsteg.pdf www.waset.org/journals/waset/v50/v50-74.pdf mo.co.za/open/stegoverview.pdf www.maths.nuigalway.ie/cstudents/mcomms/.../steganography.pdf http://www.ijcaonline.org/archives/volume6/number2/1057-1378 ipublishing.co.in/jarvol1no12010/EIJAER1018.pdf faculty.ksu.edu.sa/ghazy/Steg/References/ref26-2.pdf www1.chapman.edu/~nabav100/.../ImageSteganography.pdf Kesslet, Gary C. An Overview of Steganography for the Computer Forensics Examiner, Burlington, 2004.

Hosmer, Chet. Discovering Hidden Evidence, Cortland, 2006. N.F. Johnson, S. Jajodia, Staganalysis: The Investigation of Hiding Information, IEEE, pp. 113-116, 1998. N.F. Johnson & S. Jajodia, Steganalysis of Images Created Using Current Steganography Software, in Proceeding for the Second Information Hiding Workshop, Portland Oregon, USA, April 1998, pp. 273-289.

APPENDIX (PROGRAM CODE)

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;

using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace Minor_Project { public partial class Steganography : Form { public Steganography() { InitializeComponent(); } //public values: string loadedTrueImagePath, loadedFilePath, saveToImage, DLoadImagePath, DSaveFilePath; int height, width; long fileSize, fileNameSize; Image loadedTrueImage, DecryptedImage, AfterEncryption; Bitmap loadedTrueBitmap, DecryptedBitmap; Rectangle previewImage = new Rectangle(370, 170, 400, 400); bool canPaint = false, EncriptionDone = false; byte[] fileContainer; private void EnImageBrowse_btn_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { loadedTrueImagePath = openFileDialog1.FileName; EnImage_tbx.Text = loadedTrueImagePath; loadedTrueImage = Image.FromFile(loadedTrueImagePath); height = loadedTrueImage.Height; width = loadedTrueImage.Width; loadedTrueBitmap = new Bitmap(loadedTrueImage); canPaint = true; this.Invalidate(); } }

private string smalldecimal(string inp, int dec) { int i; for (i = inp.Length - 1; i > 0; i--) if (inp[i] == '.') break; try { return inp.Substring(0, i + dec + 1); } catch { return inp; } }

private void EnFileBrowse_btn_Click(object sender, EventArgs e) { if (openFileDialog2.ShowDialog() == DialogResult.OK) { loadedFilePath = openFileDialog2.FileName; EnFile_tbx.Text = loadedFilePath; FileInfo finfo = new FileInfo(loadedFilePath); fileSize = finfo.Length; fileNameSize = justFName(loadedFilePath).Length; } } private void Encrypt_btn_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { saveToImage = saveFileDialog1.FileName; } else return; if (EnImage_tbx.Text == String.Empty || EnFile_tbx.Text == String.Empty) { MessageBox.Show("Encrypton information is incomplete!\nPlease complete them first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (8 * ((height * (width / 3) * 3) / 3 - 1) < fileSize + fileNameSize) { MessageBox.Show("File size is too large!\nPlease use a larger image to hide this file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } fileContainer = File.ReadAllBytes(loadedFilePath); EncryptLayer(); } private void EncryptLayer() { toolStripStatusLabel1.Text = "Encrypting... Please wait!"; Application.DoEvents(); long FSize = fileSize; Bitmap changedBitmap = EncryptLayer(8, loadedTrueBitmap, 0, (height * (width/3)*3) / 3 - fileNameSize - 1, true); FSize -= (height * (width / 3) * 3) / 3 - fileNameSize - 1; if(FSize > 0) { for (int i = 7; i >= 0 && FSize > 0; i--) { changedBitmap = EncryptLayer(i, changedBitmap, (((8 - i) * height * (width / 3) * 3) / 3 - fileNameSize - (8 - i)), (((9 - i) * height * (width / 3) * 3) / 3 - fileNameSize - (9 - i)), false); FSize -= (height * (width / 3) * 3) / 3 - 1; } } changedBitmap.Save(saveToImage); toolStripProgressBar1.Increment(100); toolStripStatusLabel1.Text = "Encrypted image has been saved successfully.";

MessageBox.Show("Encrypted image has been saved successfully!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); EncriptionDone = true; AfterEncryption = Image.FromFile(saveToImage); this.Invalidate(); } private Bitmap EncryptLayer(int layer, Bitmap inputBitmap, long startPosition, long endPosition, bool writeFileName) { Bitmap outputBitmap = inputBitmap; layer--; int i = 0, j = 0; long FNSize = 0; int count = 0; bool[] t = new bool[8]; bool[] rb = new bool[8]; bool[] gb = new bool[8]; bool[] bb = new bool[8]; Color pixel = new Color(); byte r, g, b; if (writeFileName) { FNSize = fileNameSize; string fileName = justFName(loadedFilePath); //write fileName: for (i = 0; i < height && i * (height / 3) < fileNameSize; i++) for (j = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < fileNameSize; j++) { byte2bool((byte)fileName[i * (height / 3) + j / 3], ref t); pixel = inputBitmap.GetPixel(j, i); r = pixel.R; g = pixel.G; b = pixel.B; byte2bool(r, ref rb); byte2bool(g, ref gb); byte2bool(b, ref bb); if (gb[0] == true && gb[1] == true && gb[2] == true && gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true) { gb[4] = t[0]; gb[5] = t[1]; gb[6] = t[2]; gb[7] = t[3]; bb[5] = t[4]; bb[6] = t[5]; bb[7] = t[6]; rb[7] = t[7];

} else if (gb[0] == true && gb[1] == true && gb[2] == true && bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true) {

gb[5] gb[6] gb[7] bb[4]

= = = =

t[0]; t[1]; t[2]; t[3];

bb[5] = t[4]; bb[6] = t[5]; bb[7] = t[6]; rb[7] = t[7];

Color result = Color.FromArgb((int)bool2byte(rb), (int)bool2byte(gb), (int)bool2byte(bb)); outputBitmap.SetPixel(j, i, result); } i--; } //write file (after file name): int tempj = j; for (; i < height && i * (height / 3) < endPosition - startPosition + FNSize && startPosition + i * (height / 3) < fileSize + FNSize; i++) for (j = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < endPosition startPosition + FNSize && startPosition + i * (height / 3) + (j / 3) < fileSize + FNSize; j++) { if (tempj != 0) { j = tempj; tempj = 0; } byte2bool((byte)fileContainer[startPosition + i * (height / 3) + j / 3 - FNSize], ref t); pixel = inputBitmap.GetPixel(j, i); r = pixel.R; g = pixel.G; b = pixel.B; byte2bool(r, ref rb); byte2bool(g, ref gb); byte2bool(b, ref bb); if (gb[0] == true && gb[1] == true && gb[2] == true && gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true) { gb[4] = t[0]; gb[5] = t[1]; gb[6] = t[2]; gb[7] = t[3]; bb[5] = t[4]; bb[6] = t[5]; bb[7] = t[6]; rb[7] = t[7];

} else if (gb[0] == true && gb[1] == true && gb[2] == true && bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true) {

gb[5] gb[6] gb[7] bb[4]

= t[0]; = t[1]; = t[2]; = t[3];

} Color result = Color.FromArgb((int)bool2byte(rb), (int)bool2byte(gb), (int)bool2byte(bb)); outputBitmap.SetPixel(j, i, result); } long tempFS = fileSize, tempFNS = fileNameSize; r = (byte)(tempFS % 100); tempFS /= 100; g = (byte)(tempFS % 100); tempFS /= 100; b = (byte)(tempFS % 100); Color flenColor = Color.FromArgb(r, g, b); outputBitmap.SetPixel(width - 1, height - 1, flenColor); r = (byte)(tempFNS % 100); tempFNS /= 100; g = (byte)(tempFNS % 100); tempFNS /= 100; b = (byte)(tempFNS % 100); Color fnlenColor = Color.FromArgb(r, g, b); outputBitmap.SetPixel(width - 2, height - 1, fnlenColor); } return outputBitmap;

bb[5] = t[4]; bb[6] = t[5]; bb[7] = t[6]; rb[7] = t[7];

private void DecryptLayer() { toolStripStatusLabel1.Text = "Decrypting... Please wait"; Application.DoEvents(); int i, j = 0; bool[] t = new bool[8]; bool[] rb = new bool[8]; bool[] gb = new bool[8]; bool[] bb = new bool[8]; Color pixel = new Color(); byte r, g, b; pixel = DecryptedBitmap.GetPixel(width - 1, height - 1); long fSize = pixel.R + pixel.G * 100 + pixel.B * 10000; pixel = DecryptedBitmap.GetPixel(width - 2, height - 1); long fNameSize = pixel.R + pixel.G * 100 + pixel.B * 10000; byte[] res = new byte[fSize]; string resFName = ""; byte temp; //Read file name: for (i = 0; i < height && i * (height / 3) < fNameSize; i++)

for (j = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < fNameSize; j++) { pixel = DecryptedBitmap.GetPixel(j, i); r = pixel.R; g = pixel.G; b = pixel.B; byte2bool(r, ref rb); byte2bool(g, ref gb); byte2bool(b, ref bb); if (gb[0] == true && gb[1] == true && gb[2] == true && gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true) { t[0] = gb[4]; t[1] = gb[5]; t[2] = gb[6]; t[3] = gb[7]; t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); resFName += (char)temp; } else if (gb[0] == true && gb[1] == true && gb[2] == true && bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true) { t[0] t[1] t[2] t[3] = = = = gb[5]; gb[6]; gb[7]; bb[4];

t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); resFName += (char)temp; } }

//Read file on layer 8 (after file name): int tempj = j; i--; for (; i < height && i * (height / 3) < fSize + fNameSize; i++) for (j = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < (height * (width / 3) * 3) / 3 - 1 && i * (height / 3) + (j / 3) < fSize + fNameSize; j++) { if (tempj != 0) { j = tempj; tempj = 0; } pixel = DecryptedBitmap.GetPixel(j, i);

r = pixel.R; g = pixel.G; b = pixel.B; byte2bool(r, ref rb); byte2bool(g, ref gb); byte2bool(b, ref bb); if (gb[0] == true && gb[1] == true && gb[2] == true && gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true) { t[0] = gb[4]; t[1] = gb[5]; t[2] = gb[6]; t[3] = gb[7]; t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 - fNameSize] = temp;

} else if (gb[0] == true && gb[1] == true && gb[2] == true && bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true) { t[0] t[1] t[2] t[3] = = = = gb[5]; gb[6]; gb[7]; bb[4];

} } //Read file on other layers: long readedOnL8 = (height * (width / 3) * 3) / 3 - fNameSize - 1; for (int layer = 6; layer >= 0 && readedOnL8 + (6 - layer) * ((height * (width / 3) * 3) / 3 - 1) < fSize; layer--) for (i = 0; i < height && i * (height / 3) + readedOnL8 + (6 - layer) * ((height * (width / 3) * 3) / 3 - 1) < fSize; i++) for (j = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) + readedOnL8 + (6 layer) * ((height * (width / 3) * 3) / 3 - 1) < fSize; j++) { pixel = DecryptedBitmap.GetPixel(j, i); r = pixel.R; g = pixel.G; b = pixel.B; byte2bool(r, ref rb); byte2bool(g, ref gb); byte2bool(b, ref bb); if (gb[0] == true && gb[1] == true && gb[2] == true && gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true) {

t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 - fNameSize] = temp;

t[0] = gb[4]; t[1] = gb[5]; t[2] = gb[6]; t[3] = gb[7]; t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 + (6 - layer) * ((height * (width / 3) * 3) / 3 - 1) + readedOnL8] = temp; } else if (gb[0] == true && gb[1] == true && gb[2] == true && bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true) { t[0] = gb[5]; t[1] = gb[6]; t[2] = gb[7]; t[3] = bb[4]; t[4] = bb[5]; t[5] = bb[6]; t[6] = bb[7]; t[7] = rb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 + (6 - layer) * ((height * (width / 3) * 3) / 3 - 1) + readedOnL8] = temp; } } if (File.Exists(DSaveFilePath + "\\" + resFName)) { MessageBox.Show("File \"" + resFName + "\" already exist please choose another path to save file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else File.WriteAllBytes(DSaveFilePath + "\\" + resFName, res); toolStripStatusLabel1.Text = "Decrypted file has been successfully saved."; Application.DoEvents(); } private void byte2bool(byte inp, ref bool[] outp) { if(inp>=0 && inp<=255) for (short i = 7; i >= 0; i--) { if (inp % 2 == 1) outp[i] = true; else outp[i] = false; inp /= 2; } else throw new Exception("Input number is illegal."); } private byte bool2byte(bool[] inp) { byte outp = 0;

for (short i = 7; i >= 0; i--) { if (inp[i]) outp += (byte)Math.Pow(2.0, (double)(7-i)); } return outp;

private void Decrypt_btn_Click(object sender, EventArgs e) { if (DeSaveFile_tbx.Text == String.Empty || DeLoadImage_tbx.Text == String.Empty) { MessageBox.Show("Text boxes must not be empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return;

if (System.IO.File.Exists(DeLoadImage_tbx.Text) == false) { MessageBox.Show("Select image file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DeLoadImage_tbx.Focus(); return; } DecryptLayer(); } private void DeLoadImageBrowse_btn_Click(object sender, EventArgs e) { if (openFileDialog3.ShowDialog() == DialogResult.OK) { DLoadImagePath = openFileDialog3.FileName; DeLoadImage_tbx.Text = DLoadImagePath; DecryptedImage = Image.FromFile(DLoadImagePath); height = DecryptedImage.Height; width = DecryptedImage.Width; DecryptedBitmap = new Bitmap(DecryptedImage); canPaint = true; this.Invalidate(); } }

private void DeSaveFileBrowse_btn_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { DSaveFilePath = folderBrowserDialog1.SelectedPath; DeSaveFile_tbx.Text = DSaveFilePath; } } private void Form1_Paint(object sender, PaintEventArgs e) { if(canPaint) try {

} catch { e.Graphics.DrawImage(DecryptedImage, previewImage); } } private string justFName(string path) { string output; int i; if (path.Length == 3) // i.e: "C:\\" return path.Substring(0, 1); for (i = path.Length - 1; i > 0; i--) if (path[i] == '\\') break; output = path.Substring(i + 1); return output; } private string justEx(string fName) { string output; int i; for (i = fName.Length - 1; i > 0; i--) if (fName[i] == '.') break; output = fName.Substring(i + 1); return output; } private void Close_btn_Click(object sender, EventArgs e) { this.Close(); } } }

if (!EncriptionDone) e.Graphics.DrawImage(loadedTrueImage, previewImage); else e.Graphics.DrawImage(AfterEncryption, previewImage);

You might also like