Top Banner

of 84

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

ThesisOnDesigning a NP complete algorithm for image steganography & evaluating its performance with other techniquesSubmitted in the partial fulfillment of the requirements for the award of degree inMaster of Technology(Computer Engineering)

A thesis to be submitted byManu(College roll no.-11mc006)Under the esteemed Guidance ofMrs. Nidhi Sharma(Assistant professor in Computer Engineering Department)(The Technological Institute of Textile &Sciences, Bhiwani)

The Technological Institute of Textile & Sciences, Bhiwani.Affiliated to Maharishi Dayanand University, Rohtak.Session - 2011-2013AbstractIn this thesis the principles of steganography and uses of image steganography are discussed. In the main part of this work the image steganography is explained and methods of hashing are described. This report deals with image steganography as well as with the different security issues, complexity, and general overview of cryptography, steganography and digital watermarking approaches. Also it provides in-depth discussions of stenographic algorithms like Least Significant Bit (LSB) algorithm. It also compares those algorithms in terms of speed, accuracy, security and reduction in complexity. It also offers a chance to put the theory into practice by way of a piece of software designed to maximize learning in the fields. This work can therefore be split into two parts: Research and Software Development.

Table of contentsABSTRACT 1 INTRODUCTION1.1 An overview of Internet Security1.2 Where Steganography & Cryptography fits1.3 Literature Survey1.3.1 Information Security1.3.2 Security Attacks1.3.3 Analysis of various Stenographic Algorithms1.3.3.1 Steganography Methods1.3.3.2 Steganography Algorithms1.3.4 Cryptographic Algorithms1.4 Applications of our project1.5 Proposed Solution Strategy2. SOFTWARE REQUIREMENT SPECIFICATION DOCUMENT (SRS)2.1Introduction2.1.1 Purpose2.1.2 Definitions2.2OverallDescription2.2.1Product Function2.2.2 User Characteristics2.2.3 Dependencies2.3Functional Requirements2.3.1 Use Case Diagram2.3.2 Use Case Specification2.3.3 Performance Requirements2.4 Non Functional Requirements2.4.1 Performance2.4.2 Reliability2.4.3 Portability2.5 Data Flow Diagrams2.5.1 Level 0 Data Flow Diagram2.5.2 Level 1 Data Flow Diagram2.5.3 Level 2 Data Flow Diagram2.6 Activity Diagram 3. STRATEGY3.1Overview3.2 Intentions & Considerations3.3 Development Tools3.4 Visual Basic3.5 Features of the proposed method3.6 Interface Screenshots4. SOFTWARE TESTING5. RESULTS AND CONCLUSION5.1 Result5.2 Conclusion5.3 Future WorkREFERENCEAPPENDIX

CHAPTER 1INTRODUCTION

1.1 An overview of Internet SecuritySince the rise of the Internet one of the most important factors of information technology and communication has been the security of information. Everyday tons of data are transferred through the Internet through e-mail, file sharing sites, social networking sites etc. to name a few. As the number of Internet users rises, the concept of Internet security has also gain importance. The fiercely competitive nature of the computer industry forces web services to the market at a breakneck pace, leaving little or no time for audit of system security, while the tight labor market causes Internet project development to be staffed with less experienced personnel, who may have no training in security. This combination of market pressure, low unemployment, and rapid growth creates an environment rich in machines to be exploited, and malicious users to exploit those machines.1.2 Where Steganography & Cryptography fits inCryptography was created as a technique for securing the secrecy of communication and many different methods have been developed to encrypt and decrypt data in order to keep the message secret. Unfortunately it is sometimes not enough to keep the contents of a message secret, it may also be necessary to keep the existence of the message secret. The technique used to implement this, is called steganography.The word "Steganography" is of Greek origin and means "covered or hidden writing". The main aim in steganography is to hide the very existence of the message in the cover medium. Steganography and cryptography are counter parts in digital security the obvious advantage of steganography over cryptography is that messages do not attract attention to themselves, to messengers, or to recipients. Also, the last decade has seen an exponential growth in the use of multimedia data over the Internet. These include Digital Images, Audio and Video files. This rise of digital content on the internet has further accelerated the research effort devoted to steganography. The initial aim of this study was to investigate steganography and how it is implemented. Based on this work a number of common methods of steganography could then be implemented and evaluated. The strengths and weaknesses of the chosen methods can then be analyzed. To provide a common frame of reference all of the steganography methods implemented and analyzed used BMP images. To make a stenographic communication even more secure the message can be encrypted before being hidden in the carrier. Cryptography and steganography can be used together. The random looking message which would result from encryption would also be easier to hide than a message with a high degree of regularity.Therefore encryption is recommended in conjunction with steganography.1.3 Literature Survey1.3.1 Information SecurityIn general, security denotes the quality or state of being secure to be free from danger. Security is classified into different layers depending on the type of content intended to be secured:Physical security: Defines the required issues that are needed to protect the physical data or objects from unauthorized intrusion.Personal security: It is defined as the security of the individuals who are officially authorized to access information about the company and its operations Operational security: It mainly relies on the protection of the information of a particular operation of the chain of activities.Communications security: The communications security encompasses the security issues regarding the organizations communication media, technology and content.Network security: The network security is responsible for safeguarding the information regarding the networking components, connections and contents.Information security: Information security is the protection of information and the systems and hardware that use, store, and transmit that information. Information security can be defined as measures adopted to prevent the unauthorized use or modification of use of data or capabilities.1.3.2 Security AttacksThe data is transmitted from source to destination which is known as its normal flow as shown in figure 1. But the hackers might hack the network in order to access or modify the original data. These types of attacks are formally known as security attacks.

Source InfoDestination Info

Figure 1. Normal Data FlowA hacker can disrupt this normal flow by implementing the different types of techniques over the data and network in following ways. They are: Interruption Interception Modification Fabrication

Interruption:Interruption is an attack by which the hackers can interrupt the data before reaching the destination. This type of attack shows the effect on availability and usually destroys the system asset and makes the data unavailable or useless.

Source InfoDestination Info

Figure 2. InterruptionInterception:Interception is one of the well-known attacks. When the network is shared that is through a local area network is connected to Wireless LAN or Ethernet it can receive a copy of packets intended for other device. On the internet, the determined hacker can gain access to email traffic and other data transfers. This type of attack shows the effect on confidentiality of data.

Destination InfoSource Info

Figure 3. Interception

Modification:This refers to altering or replacing of valid data that is needed to send to destination.This type of attacks is done usually by unauthorized access through tampering the data. It shows effect on the integrity of the data.

Destination InfoSource Info

Figure 4. ModificationFabrication:In this type, the unauthorized user places data without the interface of source code. The hacker or unauthorized person inserts the unauthorized objects by adding records to the file, insertion of spam messages etc. This type of attack effects on the Authenticity of message.There are many types of security attacks that will try to modify the original data. The main goal of any organization / individual transmitting the data is to implement security measures which include 1. Prevention2. Detection3. Response4. RecoveryPrevention: The security attacks can be prevented by using an encryption algorithm to restrict any unauthorized access to the encryption keys. Then the attacks on confidentiality of the transmitted data will be prevented.Detection: Using the intrusion detection systems for detection of unauthorized individuals logged onto a system and making the resources available to legitimate users.Response: Whenever the unauthorized attacks happen in the system, the security mechanisms can detect the process and the system can respond to make the data unavailable.Recovery: Recovery is the final approach if an attacker modifies the data or makes the data unavailable. The data can then be recovered by using backup systems, so that the integrity of the data shall not be compromised.

1.3.3 Analysis of various Stenographic AlgorithmsNow that we are aware of the various types of security vulnerabilities, the main task of our project is to address these problems by some suitable method. We have selected Steganography in our project as it is comparatively new and we felt that it can have huge impact in the field of security.

Figure 6. Block Diagram for Steganography

Steganography supports different types of digital formats that are used for hiding the data. These files are known as carriers. Depending upon the redundancy of the object, suitable formats are used. Redundancy is the process of providing better accuracy for the object that is used for display by the bits of object. The main file formats that are used for steganography are Text, images, audio and video. We have implemented the text hiding in an image (BMP) in our project.For the purpose of developing a stenographic application we went through all the stenographic methods available and decided to select Secret key Steganography for our project. All the methods are described in details below.Also we made an analysis of all the Stenographic algorithms available and compared them in terms of speed, quality of hiding and security. A detailed analysis of all the algorithms that we have studied is presented below.1.3.3.1 Steganography MethodsThe different types of stenographic techniques available are:1. Pure Steganography2. Public key Steganography3. Secret key SteganographyPure Steganography: Pure Steganography is the process of embedding the data into the object without using any private keys. This type of Steganography entirely depends upon the secrecy. This type of Steganography uses a cover image in which data is to be embedded, personal information to be transmitted, and encryption decryption algorithms to embed the message into image. These types of steganography cant provide the better security because it is easy for extracting theMessage if the unauthorized person knows the embedding method. It has one advantage that it reduces the difficulty in key sharing.

Figure 7. Pure Steganography processSecret key Steganography: Secret key Steganography is another process of Steganography which uses the same procedure other than using secure keys. It uses the individual key for embedding the data into the object which is similar to symmetric key. For decryption it uses the same key which is used for encryption. This type of Steganography provides better security compared to pure Steganography. The main problem of using this type of stenographic system is sharing the secret key. If the attacker knows the key it will be easier to decrypt and access original information.

Figure 8. Secret key Steganography Process

Public key Steganography: Public key Steganography uses two types of keys: one for encryption and another for decryption. The key used for encryption is a private key and for decryption, it is a public key and is stored in a public database

Figure 9. Public key Steganography ProcessWe have implemented the Secret Key Steganography technique in our project. The password shall be provided by the person who does the encryption and it has to be provided to decrypt the message from the image.1.3.3.2 Steganography AlgorithmsIn our project we have done an in-depth analysis of four Stenographic algorithms in terms of speed of action, quality of hiding and security. We have also implemented NP hard and NP complete algorithms in our application the details of these algorithms are given below followed by a comparison chart between the algorithms.NP-Hard and NP Complete:TheP versus NP problemis a majorunsolved problem in computer science. Informally, it asks whether every problem whose solution can be quickly verified by a computer can also be quickly solved by a computer. It was introduced in 1971 byStephen Cookin his seminal paper "The complexity of theorem proving procedures and is considered by many to be the most important open problem in the field.The informal termquicklyused above means the existence of an algorithm for the task that runs inpolynomial time. The general class of questions for which some algorithm can provide an answer in polynomial time is called "classP" or just "P". For some questions, there is no known way to find an answer quickly, but if one is provided with information showing what the answer is, it may be possible to verify the answer quickly. The class of questions for which an answer can beverifiedin polynomial time is calledNP.Consider thesubset sum problem, an example of a problem that is easy to verify, but whose answer may be difficult to compute. Given a set of integers, does some nonemptysubsetof them sum to 0? For instance, does a subset of the set{2, 3, 15, 14, 7, 10}add up to 0? The answer "yes, because{2, 3, 10, 15}add up to zero" can be quickly verified with three additions. However, there is no known algorithm to find such a subset in polynomial time (there is one, however, inexponential time, which consists of 2n-1 tries), and indeed such an algorithm can only exist if P=NP; hence this problem is inNP(quickly checkable) but not necessarily inP(quickly solvable).An answer to theP=NPquestion would determine whether problems that can be verified in polynomial time, like the subset-sum problem, can also be solved in polynomial time. If it turned out thatPNP, it would mean that there are problems inNP(such asNP-completeproblems) that are harder to compute than to verify: they could not be solved in polynomial time, but the answer could be verified in polynomial time.In this theory, the classPconsists of all thosedecision problems(definedbelow) that can be solved on a deterministic sequential machine in an amount of time that ispolynomialin the size of the input; the classNPconsists of all those decision problems whose positive solutions can be verified inpolynomial timegiven the right information, or equivalently, whose solution can be found in polynomial time on anon-deterministicmachine.Clearly,PNP.Aside from being an important problem in computational theory, a proof either way would have profound implications for mathematics, cryptography, algorithm research,artificial intelligence,game theory, multimedia processing and many other fields. The relation between thecomplexity classesPandNPis studied incomputational complexity theory, the part of thetheory of computationdealing with the resources required during computation to solve a given problem. NP contains all problems in P, since one can verify any instance of the problem by simply ignoring the proof and solving it. Since a polynomial-time machine can only read polynomially many bits, it cannot use more than polynomial space, nor can it read a proof string occupying more than polynomial space (so we don't have to consider proofs longer than this). NP is also contained in EXPTIME, since the same algorithm operates in exponential time.

Euler diagram for P, NP, NP-complete, and NP-hard set of problems.The complexity class P is contained in NP, but NP contains many important problems, the hardest of which are called NP-complete problems, for which no polynomial-time algorithms are known for solving them (although they can be verified in polynomial time). The most important open question in complexity theory, the P = NP problem, asks whether polynomial time algorithms actually exist for NP-complete. It is widely believed that this is not the case.

The proposed AlgorithmBelow is the list of steps executed by the proposed algorithm to hide a piece of secret data into an image file.1. The secret data are preprocessed so that they become suitable for storage inside the carrier image.a. The secret data, no matter their types and formats whether text, documents, or executable, are converted into a binary form resulting into a string of bits denoted by P={b0, b1, b2, b3,bn-1} where bi is a single bit composing the secret data and n is the total number of bits.b. The string of bits P is organized into chunks of 3 bits, such as P=Chunks={ N0[b0, b1, b2], N1[ b3, b4, b5], N2[b6, b7, b8],Nm-1[bn-3, bn-2, bn-1] }, where Nj is a particular 3-bit chunk, m is the total number of chunks, and n is the total number of bits making up the secret data.2. A set of carrier pixels is randomly selected from the carrier image in which every random selected pixel is denoted by Pt(xt , yt) where x and y are the coordinates of pixel P, and t is the index of P.3. The chunks of the secret data that were created in step 1.b are embedded into the randomly selected pixel of step 2.a. As the carrier image is a 24-bit colored image, every pixel would have three color components R, G, B, each of length 8 bits. For this reason, every chunk Pj is stored in the three LSBs of each of the color components of every selected carrier pixel such as Pt={ fiveMSBs(Rt) + Pj; fiveMSBs(Gt) + Cj+1 ; fiveMSBs(Bt) + Pj+2 }, where P is a randomly selected pixel, t is the index of P, and R, G, and B are the three Red-Green-Blue color components of pixel Pt. Furthermore, five MSBs(component) is a function that returns the original five most significant bits of the color component component. The + operator concatenates the original five MSBs of the color component with the 3 bits of a particular chunk, making the total number of bits in a given color component equals to 8 bits. In effect, the first 5 bits are the original five MSBs of the color component and the three LSBs are a particular chunk from the secret data.4. The coordinates of the randomly selected pixels of step 2 are encoded into English sentences each of which is denoted by Sk.a. Every single digit of the coordinates x and y such as x={d0,d1,d2,dr-1} and y={d0,d1,d2,dr-1} is mapped into a category number of the lexicon. For instance, P(29, 01) is encoded using the CFG of Figure 2 and the lexicon of Table 1 as a book from school. In that, a is a determinant from category 2, book is a noun from category 9, from is a preposition from category 0, and school is a noun from category 1.b. Step 4.a is repeated for all selected pixels. Eventually, the number of all generated English sentences would be equal to the number of all randomly selected pixels.5. The final output comprises two mediums. The first one is the carrier image which houses the secret data into its randomly selected pixels such as IMG={P0,P1,P2,Pt-1}, where P is a carrier pixel and t is the total number of carrier pixels; while, the second one is an English text made up of grammatically correct English sentences such as T={S0,S1,S2,St-1}, where S is an English sentence and t is the total number of English sentences which is also equal to the total number of carrier pixels. Both, the carrier image and the English text are to be sent to the receiver, not necessarily at the same time, however, they should be both present when the receiver is uncovering the secret data.

LSB algorithm:LSB (Least Significant Bit) substitution is the process of adjusting the least significant bit pixels of the carrier image. It is a simple approach for embedding message into the image. The Least Significant Bit insertion varies according to number of bits in an image. For an 8 bit image, the least significant bit i.e., the 8th bit of each byte of the image is changed to the bit of secret message. For 24 bit image, the colors of each component like RGB (red, green and blue) are changed. LSB is effective in using BMP images since the compression in BMP is lossless. But for hiding the secret message inside an image of BMP file using LSB algorithm it requires a large image which is used as a cover. LSB substitution is also possible for GIF formats, but the problem with the GIF image is whenever the least significant bit is changed the whole color palette will be changed. The problem can be avoided by only using the gray scale GIF images since the gray scale image contains 256 shades and the changes will be done gradually so that it will be very hard to detect. For JPEG, the direct substitution of stenographic techniques is not possible since it will use loss compression. So it uses LSB substitution for embedding the data into images. There are many approaches available for hiding the data within an image: one of the simple least significant bit submission approaches is Optimum Pixel Adjustment Procedure. The simple steps for OPA explain the procedure of hiding the sample text in an image.Step1: A few least significant bits (LSB) are substituted with in data to be hidden.Step2: The pixels are arranged in a manner of placing the hidden bits before the pixel of each cover image to minimize the errors.Step3: Let n LSBs be substituted in each pixel.Step4: Let d= decimal value of the pixel after the substitution.d1 = decimal value of last n bits of the pixel.d2 = decimal value of n bits hidden in that pixel.Step5: If (d1~d2)=1000) as the KeyStep 5: Divide the reversed number with the divisorStep 6: Store the remainder in first 3 digits & quotient in next 5 digits (remainder and quotient wouldnt be more than 3 digits and 5 digits long respectively. If any of these are less than 3 and 5 digits respectively we need to add required number of 0s (zeros) in the left hand side. So, this would be the cipertext i.e. encrypted text.Now store the remainder in first 3 digits & quotient in next 5 digits.

The decryption algorithm:Step 1: Multiply last 5 digits of the cipher text by the KeyStep 2: Add first 3 digits of the cipher text with the result produced in the previous stepStep 3: If the result produced in the previous step i.e. step 2 is not an 8-bit number we need to make it an 8- bit number Step 4: Reverse the number to get the original text i.e. the plain text Example showing the above algorithm in action Let, the character is T. Now according to the steps we will get the following:Step 1: ASCII of T is 84 in decimal.Step 2: The Binary value of 84 is 1010100. Since it is not an 8 bit binary numbers we need to make it 8 bit number as per the encryption algorithm. So it would be0 1 0 1 0 1 0 0Step 3: Reverse of this binary number would be 0 0 1 0 1 0 1 0Step 4: Let 1000 as divisor i.e. KeyStep 5: Divide 00101010 (dividend) by 1000(divisor)Step 6: The remainder would be 10 and the quotient would be 101. So as per the algorithm the cipher text would be 01000101 which is ASCII 69 in decimal i.e. E 0 1 0 0 0 1 0 1 to decode:Step 1: After multiplying 00101 (last 5 digits of the cipher text) by 1000 (Key) the result would be 1 0 1 0 0 0Step 2: After adding 010 (first 3 digits of the ciphertext) with 101000 the result would be 1 0 1 0 1 0Step 3: Since 101010 is not an 8-bit number we need to make it 0 0 1 0 1 0 1 0Step 4: After reversing the number it would be 01010100 i.e. ASCII 84 in decimal i.e. T as character which was the original text 0 1 0 1 0 1 0 0Algorithm 2Apart from the algorithm mentioned above, we have also used another encryption algorithm which is the Rail Fence Encryption cipher. This simple transposition cipher scrambles the letters of the plaintext (in our case the text encrypted through the above algorithm) without causing any change to the original characters.Example: If the string to be encrypted is suppose Hello World then performing a depth-2 Rail Fence cipher will change it to HloWrdel olAlgorithm 3After the message and the password have passed through the ciphers described above they are XORed together to form a single string. To perform XOR operation we find the ASCII value for both the text and the password and then perform binary XOR operation on them. After that we change it back again to String.Example: The XOR operation between the text Hello World and password 12345 gives us the following string: yW_XZe\FYU.Only after the message has passed through these encryption parts are they embedded in the image using one of the steganography algorithm described above.

1.4 Applications of our project1. Confidential communication and secret data storing2. Protection of data alteration3. Access control system for digital content distribution1.5 Proposed Solution StrategyWe have created a simple UI wherein the user has the ability to enter the text he wants to hide via a Textbox. After that he is given the opportunity to choose a picture which he wants to use as carrier image.The system has an inbuilt checker which will check if the image format (BMP in our case) is correct and if the image size is big enough to hide the text. Very small images (< 64*64) are not allowed to be imported.The user can then enter his password which he wants to use to encrypt the image. An additional confirm password box is created so that there is no typing mistakes. User can also choose to see the internal proceedings of the software (the encryption part) or he can choose a basic view for the application.For decrypting an image, a user simply has to choose the image which he wants to decode and provide the correct password. The decrypted text will then be shown to him. He will have the option to then save the text in an external text file.An extensive user manual is written for the help of the user.

CHAPTER 2SOFTWARE REQUIREMENT SPECIFICATION DOCUMENT (SRS)

2.1 Introduction2.1.1 PurposeWe have chosen to use Steganography as our project as it is somewhat new in the field of security and we felt that it could have a huge impact in the future (if not already). The main purpose of our project is to create a user-friendly application which can solve the security concerns in message passing at least to some extent.2.1.2 DefinitionsAll the definitions are explained in Appendix A.2.2 Overall Description2.2.1 Product FunctionThere is only one kind of user for our product. The general user will be able to perform all the operations on the product after installing the product on his machine. Microsoft .NET Framework 4.0 or higher is required to install the product.

2.2.2 User CharacteristicsAny user with a little knowledge of computers and security will be able to operate our application.2.2.3 DependenciesThe system only depends on the fact that Microsoft .NET Framework 3.0 or higher is installed. Also BMP images of reasonable size are required to carry out Steganography.2.3 Functional Requirements2.3.1 Use Case DiagramEMPORT A FILE FOR A ENCRYPTION

EMPORT A FILE FOR DESCRPTION

ENTER TEXT TO BE EMBEDDED

PERFORMANCE ENCRYPTION/ DECREPTION

GEHIDE THE SECRETEXIT THE APPLICATIONCHOOSE THE STENOGRAPHY ALGORITHMSAVE DECRPTED TEXT IN A TEXT FILECHOOSE BETWEEN BASIC AND ADVANCED VIEWGENERAL USER

2.3.2 Use Case Specification Primary actor: The general targeted audience is the only primary users for our system. Pre condition: Microsoft .NET framework 4.0 is installed.The user has to import an image and has to provide the text. Main Scenarios: There are a number of main scenarios in our project.1. Import an image for encryption.2. Import an image for decryption.3. Choose between the basic and the advanced view.4. The user can see a detailed help file in .chm format.5. Save decrypted file in a textbox.6. Clear the boxes for new encryption.2.3.3 Performance RequirementsA computer running Windows XP/Vista/7 is required for the application to run. Microsoft .NET Framework 4.0 or higher is required. A keyboard or a mouse is required to operate the application.

2.4 Non Functional Requirements2.4.1 PerformanceThe embedded image generated should not contain any distortion. Also the application should be secure to statistical and comparison steganalysis.2.4.2 ReliabilityThe product should not crash under any circumstance such as user entering invalid values, user trying to load unsupported files etc. It should show appropriate message for every user generated message.2.4.3 PortabilityOur product will be portable to carry and will run in any machine provided it runs a Windows Operating System. We have created an installer which compiles all files into a single executable (.msi). Only this file is required to successfully install the application on any computer.2.5 Data Flow DiagramsData flow diagrams are the basic building blocks that define the flow of data in a system to the particular destination and difference in the flow when any transformation happens. It makes whole procedure like a good document and makes simpler and easy to understand for both programmers and non-programmers by dividing into the sub process.The data flow diagrams are the simple blocks that reveal the relationship between various components of the system and provide high level overview, boundaries of particular system as well as provide detailed overview of system elements.The data flow diagrams start from source and ends at the destination level i.e., it decomposes from high level to lower levels. The important things to remember about data flow diagrams are: it indicates the data flow for one way but not for loop structures and it doesnt indicate the time factors.

This section reveals about the data flow analysis which states about data that have been used, classification of data flow diagrams based on their functions and the other different levels used in the project.Data flow processes:It will define the direction i.e., the data flow from one entity to another entity.Process:Process defines the source from where the output is generated for the specified input. It states the actions performed on data such that they are transformed, stored or distributed.Data store:It is the place or physical location where the data is stored after extraction from the data source.Source:It is the starting point or destination point of the data, stating point from where the external entity acts as a cause to flow the data towards destination.

2.5.1 Level 0 Data Flow DiagramDFD level 0 is the highest level view of the system, contains only one process which represents whole function of the system. It doesnt contain any data stores and the data is stored with in the process.For constructing DFD level 0 diagram for the proposed approach we need two sources one is for source and another is for destination and a process.DestinationSource0.0Personal Data

Figure 11. Level 0 Data Flow DiagramDFD level 0 is the basic data flow process, the main objective is to transfer the data from sender to receiver after encryption.

2.5.2 Level 1 Data Flow Diagram1.0Encrypted Phase

2.0Transmission Phase3.0Description Phase0.0Secret Data

Figure 12. Level 1 Data Flow Diagram

In this data flow diagram, the secret data is sent to the encryption phase for embedding the data into the image for generating the carrier image. In the next phase the carrier image is sent to the decryption phase through the transmission phase. The final phase is the decryption phase where the data is extracted from the image and displays the original message.

2.5.3 Level 2 Data Flow DiagramThe image and the text document are given to the encryption phase. The encryption algorithm is used for embedding the data into the image.The resultant image acting as a carrier image is transmitted to the decryption phase using the transmission medium. For extracting the message from the carrier image, it is sent to the decryption section. The plain text is extracted from the carrier image using the decryption algorithm.1.0Encryption3.0Description 2.0Transmission

DecryptionAlgorithmPlain TextPlane TextCareer ImageEncryptionAlgorithm

Figure 13. Level 2 Data Flow Diagram

2.6 Activity DiagramDecryption AlgorithmEncryption AlgorithmPlain TextReceiverCarrier ImageSender

(Image, Text File)

Stenography Module

Figure 14. Activity DiagramThe sender sends the message to the receiver using three phases. Since we are using the stenographic approach for transferring the message to the destination, the sender sends text as well as image file to the primary phase i.e., to encryption phase.The encryption phase uses the encryption algorithm by which the carrier image is generated. The encryption phase generates the carrier image as output.The carrier image is given as input to the next phase i.e., to decryption phase. The decryption phase uses the decryption algorithm for decrypting the original textfrom the image so that the decryption phases generate plain text. The plain text is then sent to the receiver using the transmission media.

CHAPTER 3DESIGN STRATEGY3.1 OverviewThe software development portion of this project focuses on an implementation of most of the stenographic techniques as described in Part I. This means that the end-product will provide a means for its users to embed a message within an image using one of several different stenographic algorithms this chapter provides details of the aims and objectives of the development portion of the project, and also discusses the methodologies and design principles that were considered whilst building the system.3.2 Intentions & ConsiderationsThe end-product is intended to aid an education in the fields of steganography. As the range of end-user can range from a complete novice to a more advanced user (in terms of their prior knowledge in the research area), the end-product will provide a Graphical User Interface (GUI) in order to accommodate all user types.By developing the functions such that they are self-contained, it is possible that they can be used in association with an external bulk processing function in order to obtain results from a wide selection of source images very quickly. If this can be achieved successfully, the system will not only appeal to students who wish to learn more about steganography, it will also mean that the tools are useful for steganalysis in a more active capacity. Subsequently, whilst the main focus was on producing a good user interface for each of the functions, attention was also paid to ensuring the longevity of the system as a whole.Also, by developing the functions in this manner, it means that new functions can easily be added that can operate alongside the existing functions. Thus, over time, the system has the potential to be highly desirable in the field of steganalysis.

3.3 Development ToolsWe have chosen to use Microsoft .NET to build this application. Microsoft .NET is a framework developed by Microsoft in the year 2002. The main aim of the .NET framework is to build web and user interactive GUI (Graphical User Interface) applications. The Windows forms web application classes that are used for creating new windows form based applications. Microsoft .NET is a user friendly language which helps us build the required web application easily. So, we preferred using the .NET framework over the other enterprise frameworks. Some features of .NET are: .NET framework acts as a common platform for building, organizing, and running web applications and web services. .NET has common libraries like ASP.NET, ADO.NET and Windows Forms. .NET supports multiple languages like C, C#, Visual Basic, Jscript. .NET is a user friendly language and is easy to learn compared to other languages for example JAVA because in .NET the coding is very easier. .NET supports additional data sources of ADO.NET like Oracle and ODBC. Using .NET platform we can build web applications as required, the applications are highly secure because it uses access control lists and security identifiers. Common Language Runtime (CLR) is heart to .NET framework. CLR is same as JVM (JAVA Virtual Machine) in .NET, .NET program runs only on platforms that support CLR. Now, in this project we have chosen Microsoft .NET platform for building this Windows based stenographic application. The main components of .NET which used in this project are Visual Basic 2010.

3.4 Visual BasicVisual Basic is the one of the component in Microsoft Visual studio which works similar to Visual C#. Creating applications using Visual Basic is easier compared to the JAVA. In order to create the application, we need to use the designer tool and tool box so that required tool like radio button, text boxes etc., can be placed. After designing the next phase is to relate them with specified functions. This can be done using Visual Basic coding. The coding can be done by double clicking in the elements on the designer tool. The program or code which is written using VB language is saved with .vb extension. The code can be compiled using Debug option. When we click on debug option the .NET architecture creates the class file. After creation of class file, Common Language Runtime (CLR) converts the class file into the machine language that is compatible with the hardware since CLR supports cross-language integration. The code as such can be compiled on any other operating system. Microsoft visual studio provides a bunch of tools for creating Windows as well as web applications.

3.5 Features of the proposed methodIn this project, the proposed method should provide better security when transmitting or transferring the data or messages from one end to another. The main objective of the project is to hide the message or a secret data into an image which further act as a carrier of secret data and to transmit to the destination securely without any modification. If there are any perceivable changes when we are inserting or embedding the information into the image or if any distortions occur in the image or on its resolution there may be a chance for an unauthorised person to modify the data.So, the data encryption into an image and decryption and steganography plays a major role in the project.The three important sections in the project are: Encryption: Encryption is done to provide an extra security level to our application. Even if the secret is compromised and someone came to know that there is some secret data in the image, he still cannot view it because of the encryption. Steganography: The steganography part is done using the algorithms described above. The main feature of steganography is that the picture should not be distorted and the size of the original image to the modified image should remain the same. Decryption: The decryption part is completely opposite to the encryption part described above. It requires the user to provide a correct password and the data in the image will decrypted.

3.6 Interface ScreenshotsThe GUI for our software has been kept simple so that every user ranging from the novice to the most advanced can use it with no difficulty. There is very little scope for error for the user since all actions are monitored and all errors are reported. The software is also very fast and does the steganography typically within 2 seconds. Since we use only BMP files for our project, if a user tries to import any other file type he is prompted of his error. All the aspects of our interface are described using snapshots in the next few pages.3.6.1 The main interfaceBrowse image for load and select an image.

Load a file foe encryption.

Create a folder to encrypt a file.

Encryption image done successfully

For decrypt image

Load an image and save file to new folder

Description file is done successfully.

CHAPTER 4SOFTWARE TESTING 4.1 IntroductionTesting defines the status of the working functionalities of any particular system. Through testing particular software one cant identify the defects in it but can analyses the performance of software and its working behavior. By testing the software we can find the limitations that become the conditions on which the performance is measured on that particular level. In order to start the testing process the primary thing is requirements of software development cycle. Using this phase the testing phase will be easier for testers.The capacity of the software can be calculated by executing the code and inspecting the code in different conditions such as testing the software by subjecting it to different sources as input and examining the results with respect to the inputs.After the designing phase, the next phase is to develop and execute the code in different conditions for any errors and progress to the developing phase. Without testing and execution, the software cannot be moved to the developing phase. There are two types of testing. The functional testing, which defines the specified function of a particular code in the program. This type of testing gives us a brief description about the programs performance and security in the various functional areas.The other type of testing is non-functional testing. Non-functional testing defines the capabilities of particular software like its log data etc. It is opposite to functional testing and so will not describe the specifications like security and performance.The performance of the particular program not only depends on errors in coding. The errors in the code can be noticed during execution, but the other types of errors can affect the program performance like when the program is developed based on one platform that may not perform well and give errors when executed in different platform. So, compatibility is another issue that reduces the software performance. The code tuning helps us in optimizing the program to perform at its best utilizing minimal resources possible under varied conditions.4.2 Aim of TestingThe main aim of testing is to analyses the performance and to evaluate the errors that occur when the program is executed with different input sources and running in different operating environments.In this project, we developed a stenographic application based on Microsoft Visual Studio which focuses on data hiding based on various algorithms. The main aim of testing in this project is to find the compatibility issues as well as the working performance when different sources are given as the inputs.4.3 Test CasesTests have been performed throughout the implementation of the application. When the tests have found an error, the problem was found and resolved. The following tests cases were done after the system was completed.

CHAPTER 5RESULTS AND CONCLUSION5.1 ResultThe Stereographic schemes which were present for more than 1000 years were studied and analyzed in details in this report. Various algorithms were analyzed, compared and implemented.For designing the stenographic application, we worked on different phases like encryption, decryption and data transmission. An application for sending the personal data securely to the destination has been developed successfully.The design phase is the primary phase, which gives a brief idea about the different levels used for developing an application with the help of block diagrams.The software is designed in a user friendly manner. So, it is simple to use for developing a prototype of the application.The most important phase in the project is the execution phase. The execution phase is developed with the help of design phase. For executing the application, we worked on two sections: one is encryption and another is decryption. As we designed the program using .NET platform, the next part is debugging the program. We faced some problems when writing the code, but at last we were successful in executing the program without errors. We used different approaches for testing the application, which helped us to know about the limitations.In this project we mainly concentrated on embedding the data into an image. We have designed the stenographic application which embedded the data into the image. Normally, after embedding the data into the image, the image may lose its resolution. In the proposed approach, the image remains unchanged in its resolution as well in size. The speed of embedding the data into the image is also high in the proposed approach such that the image is protected and the data to the destination is sent securely. For the decryption phase, we have used the same .NET programming language for the purpose of designing. We have used security keys like personal password for protecting the image from unauthorized modification, which improved the security level.We have chosen image steganography because it is simple to use and its user friendly application. There are many applications for image hiding but the proposed approach is created using Microsoft .NET frame work which is easier for coding and the performance is better compared to other languages.5.2 ConclusionIn the present world, the data transfers using internet is rapidly growing because it is so easier as well as faster to transfer the data to destination. So, many individuals and business people use to transfer business documents, important information using internet. Security is an important issue while transferring the data using internet because any unauthorized individual can hack the data and make it useless or obtain information un- intended to him.The proposed approach in this project uses a new stenographic approach called image steganography. The application creates a stego image in which the personal data is embedded and is protected with a password which is highly secured.5.3 Future WorkThe future work on this project will be to improve the compression ratio of the image to the text. This project can be extended to a level such that it can be used or the different types of image format like .bmp, .jpeg, .tif etc., in the future.Further the GUI can be refined and made more users friendly. Also a command line version can be developed for this application so that it will suit the more experienced users.

REFRENCES[1] Jonathan B.Knudsen, Java Cryptography.O'REILLY'.[2] Matt J.B. Robshaw, Stream Ciphers Technical Report TR-701.: RSA Laboratories.[3] Fred Piper Thomas Beth, The Stop-and-Go Generator..[4] P. Prasithsangaree and P. Krishnamurthy, "Analysis of Energy Consumption of RC4 and AES Algorithms in Wireless LANs," University of Pittsburgh.[5] Dhananjay K. Theckedath, Image Processing using MATLAB codes.

[6] Y.B. Mao,G. Chen. S.G. Lian,A novel fast image Encryption scheme based on the 3D chaotic baker map,Int. j.

[7] Bifurcate Chaos, vol. 14,pp.3613-3624,2004

[8] Yas A. Alsultanny,Image encryption by cipher feedback mode, ICIC International Journal vol.3,589-596.

[9] A.Mitra,Y V.Subba Rao,and S.R.M. Prasnna, A new Image encryption approach using combinational permutation techniques, Journal of Computer Science,Vol.1,no.1,2006,p.127.

[10] A.Sinha, K.Singh, A technique foe image encryption using digital signature, Optics Communications,2003,pp. 1-6.

[11] Rafael C.Gonzalez and Richard E.Woods, Digital Image Processing, 3th ed. Addison-Wesley, 1992

[12] S.S. Maniccam, N.G. Bourbakis, Lossles Image Compression and Encryption using SCAN, Pattern Recognization, vol. 34,2001, pp.229-1245

[13] Arvind Kumar and Km. Pooja, Steganography- A Data Hiding Technique, International Journal of Computer Applications, vol. 9, No. 7, November 2010

[14] Hanbo Sun, Exploring the internal structure of a 24-bit Uncompressed Bitmap File. Available: http://www.codeguru.com.

[15] Rafael C.Gonzalez and Richard E.Woods, Digital Image Processing, 3th ed. Addison-Wesley, 1992.

[16] E. Berlekamp, R.J. McEliece, and H.C.A. van Tilborg, On the inherent intractability of certain coding problems, IEEE Trans. on Information Theory, Vol. IT24, No. 3, 1978, pp. 384386.

[17] Th. Berson, Differential cryptanalysis mod 232 with applications to MD5,Advances in Cryptology, Proc. Eurocrypt92, LNCS 658, R.A. Rueppel, Ed., Springer-Verlag, 1993, pp. 7180.

[18] C. Besnard and J. Martin, DABO: proposed additional message authentication algorithms for ISO 8731, preprint, 1992.

[19] E. Biham and A. Shamir, Differential cryptanalysis of DES-like cryptosystems, Journal of Cryptology, Vol. 4, No. 1, 1991, pp. 372.

[20] www.google.com.[21.] Wikipedia.

APPENDIX ISOURCE CODEFor browse an image and fileprivate 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);

FileInfo imginf = new FileInfo(DLoadImagePath); float fs = (float)imginf.Length / 1024; ImageSize_lbl.Text = smalldecimal(fs.ToString(), 2) + " KB"; ImageHeight_lbl.Text = DecryptedImage.Height.ToString() + " Pixel"; ImageWidth_lbl.Text = DecryptedImage.Width.ToString() + " Pixel"; double cansave = (8.0 * ((height * (width / 3) * 3) / 3 - 1)) / 1024; CanSave_lbl.Text = smalldecimal(cansave.ToString(), 2) + " KB";

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 { if (!EncriptionDone) e.Graphics.DrawImage(loadedTrueImage, previewImage); else e.Graphics.DrawImage(AfterEncryption, previewImage); } 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(); }

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http:\\\\www.programmer2programmer.net");

}

}}

For Encryptionusing System;using System.Drawing;using System.Windows.Forms;using System.IO;

namespace Text2Image{ public partial class FrmSteganography : Form { public FrmSteganography() { 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(20,160,490,470); 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);

FileInfo imginf = new FileInfo(loadedTrueImagePath); float fs = (float)imginf.Length / 1024; ImageSize_lbl.Text = smalldecimal(fs.ToString(), 2) + " KB"; ImageHeight_lbl.Text = loadedTrueImage.Height.ToString() + " Pixel"; ImageWidth_lbl.Text = loadedTrueImage.Width.ToString() + " Pixel"; double cansave = (8.0 * ((height * (width / 3) * 3) / 3 - 1)) / 1024; CanSave_lbl.Text = smalldecimal(cansave.ToString(), 2) + " KB";

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 frist.", "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); toolStripStatusLabel1.Text = "Encrypted image has been successfully saved."; 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; 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 (j % 3 == 0) { rb[7] = t[0]; gb[7] = t[1]; bb[7] = t[2]; } else if (j % 3 == 1) { rb[7] = t[3]; gb[7] = t[4]; bb[7] = t[5]; } else { rb[7] = t[6]; gb[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 (j % 3 == 0) { rb[layer] = t[0]; gb[layer] = t[1]; bb[layer] = t[2]; } else if (j % 3 == 1) { rb[layer] = t[3]; gb[layer] = t[4]; bb[layer] = t[5]; } else { rb[layer] = t[6]; gb[layer] = t[7]; } 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; }

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 (j % 3 == 0) { t[0] = rb[7]; t[1] = gb[7]; t[2] = bb[7]; } else if (j % 3 == 1) { t[3] = rb[7]; t[4] = gb[7]; t[5] = bb[7]; } else { t[6] = rb[7]; t[7] = gb[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 (j % 3 == 0) { t[0] = rb[7]; t[1] = gb[7]; t[2] = bb[7]; } else if (j % 3 == 1) { t[3] = rb[7]; t[4] = gb[7]; t[5] = bb[7]; } else { t[6] = rb[7]; t[7] = gb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 - fNameSize] = temp; } }

//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 (j % 3 == 0) { t[0] = rb[layer]; t[1] = gb[layer]; t[2] = bb[layer]; } else if (j % 3 == 1) { t[3] = rb[layer]; t[4] = gb[layer]; t[5] = bb[layer]; } else { t[6] = rb[layer]; t[7] = gb[layer]; 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= 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);

FileInfo imginf = new FileInfo(DLoadImagePath); float fs = (float)imginf.Length / 1024; ImageSize_lbl.Text = smalldecimal(fs.ToString(), 2) + " KB"; ImageHeight_lbl.Text = DecryptedImage.Height.ToString() + " Pixel"; ImageWidth_lbl.Text = DecryptedImage.Width.ToString() + " Pixel"; double cansave = (8.0 * ((height * (width / 3) * 3) / 3 - 1)) / 1024; CanSave_lbl.Text = smalldecimal(cansave.ToString(), 2) + " KB";

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 { if (!EncriptionDone) e.Graphics.DrawImage(loadedTrueImage, previewImage); else e.Graphics.DrawImage(AfterEncryption, previewImage); } 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(); }

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http:\\\\www.programmer2programmer.net");

}

}}

For Decryptionusing System;using System.Drawing;using System.Windows.Forms;using System.IO;

namespace Text2Image{ public partial class FrmSteganography : Form { public FrmSteganography() { 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(20,160,490,470); 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);

FileInfo imginf = new FileInfo(loadedTrueImagePath); float fs = (float)imginf.Length / 1024; ImageSize_lbl.Text = smalldecimal(fs.ToString(), 2) + " KB"; ImageHeight_lbl.Text = loadedTrueImage.Height.ToString() + " Pixel"; ImageWidth_lbl.Text = loadedTrueImage.Width.ToString() + " Pixel"; double cansave = (8.0 * ((height * (width / 3) * 3) / 3 - 1)) / 1024; CanSave_lbl.Text = smalldecimal(cansave.ToString(), 2) + " KB";

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 frist.", "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); toolStripStatusLabel1.Text = "Encrypted image has been successfully saved."; 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; 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 (j % 3 == 0) { rb[7] = t[0]; gb[7] = t[1]; bb[7] = t[2]; } else if (j % 3 == 1) { rb[7] = t[3]; gb[7] = t[4]; bb[7] = t[5]; } else { rb[7] = t[6]; gb[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 (j % 3 == 0) { rb[layer] = t[0]; gb[layer] = t[1]; bb[layer] = t[2]; } else if (j % 3 == 1) { rb[layer] = t[3]; gb[layer] = t[4]; bb[layer] = t[5]; } else { rb[layer] = t[6]; gb[layer] = t[7]; } 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; }

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 (j % 3 == 0) { t[0] = rb[7]; t[1] = gb[7]; t[2] = bb[7]; } else if (j % 3 == 1) { t[3] = rb[7]; t[4] = gb[7]; t[5] = bb[7]; } else { t[6] = rb[7]; t[7] = gb[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 (j % 3 == 0) { t[0] = rb[7]; t[1] = gb[7]; t[2] = bb[7]; } else if (j % 3 == 1) { t[3] = rb[7]; t[4] = gb[7]; t[5] = bb[7]; } else { t[6] = rb[7]; t[7] = gb[7]; temp = bool2byte(t); res[i * (height / 3) + j / 3 - fNameSize] = temp; } }

//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 (j % 3 == 0) { t[0] = rb[layer]; t[1] = gb[layer]; t[2] = bb[layer]; } else if (j % 3 == 1) { t[3] = rb[layer]; t[4] = gb[layer]; t[5] = bb[layer]; } else { t[6] = rb[layer]; t[7] = gb[layer]; 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= 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);

FileInfo imginf = new FileInfo(DLoadImagePath); float fs = (float)imginf.Length / 1024; ImageSize_lbl.Text = smalldecimal(fs.ToString(), 2) + " KB"; ImageHeight_lbl.Text = DecryptedImage.Height.ToString() + " Pixel"; ImageWidth_lbl.Text = DecryptedImage.Width.ToString() + " Pixel"; double cansave = (8.0 * ((height * (width / 3) * 3) / 3 - 1)) / 1024; CanSave_lbl.Text = smalldecimal(cansave.ToString(), 2) + " KB";

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 { if (!EncriptionDone) e.Graphics.DrawImage(loadedTrueImage, previewImage); else e.Graphics.DrawImage(AfterEncryption, previewImage); } catch { e.Graphics.DrawImage(DecryptedImage, previewImage); } }

private string justFName(string path) { string output;