You are on page 1of 84

Thesis

On

Designing a NP complete algorithm for image steganography & evaluating its performance with other techniques
Submitted in the partial fulfillment of the requirements for the award of degree in

Master of Technology
(Computer Engineering)

A thesis to be submitted by

Manu
(College roll no.-11mc006) Under the esteemed Guidance of

Mrs. 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-2013

Abstract In 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 contents
ABSTRACT 1 INTRODUCTION 1.1 An overview of Internet Security 1.2 Where Steganography & Cryptography fits 1.3 Literature Survey 1.3.1 Information Security 1.3.2 Security Attacks 1.3.3 Analysis of various Stenographic Algorithms 1.3.3.1 Steganography Methods 1.3.3.2 Steganography Algorithms 1.3.4 Cryptographic Algorithms 1.4 Applications of our project 1.5 Proposed Solution Strategy 2. SOFTWARE REQUIREMENT SPECIFICATION DOCUMENT (SRS) 2.1Introduction 2.1.1 Purpose 2.1.2 Definitions 2.2Overall Description 2.2.1Product Function 2.2.2 User Characteristics 2.2.3 Dependencies 2.3Functional Requirements 2.3.1 Use Case Diagram 2.3.2 Use Case Specification 2.3.3 Performance Requirements

2.4 Non Functional Requirements 2.4.1 Performance 2.4.2 Reliability 2.4.3 Portability 2.5 Data Flow Diagrams 2.5.1 Level 0 Data Flow Diagram 2.5.2 Level 1 Data Flow Diagram 2.5.3 Level 2 Data Flow Diagram 2.6 Activity Diagram 3. STRATEGY 3.1Overview 3.2 Intentions & Considerations 3.3 Development Tools 3.4 Visual Basic 3.5 Features of the proposed method 3.6 Interface Screenshots 4. SOFTWARE TESTING 5. RESULTS AND CONCLUSION 5.1 Result 5.2 Conclusion 5.3 Future Work REFERENCE APPENDIX

CHAPTER 1 INTRODUCTION

1.1 An overview of Internet Security Since 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 in Cryptography 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 Survey 1.3.1 Information Security In 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 Attacks The 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 Info

Destinatio n Info

Figure 1. Normal Data Flow

A 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 Info

Destinatio n Info

Figure 2. Interruption

Interception: 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.

Source Info

Destinatio n 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.

Source Info

Destinatio n Info

Figure 4. Modification

Fabrication: 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. Prevention 2. Detection

3. Response 4. Recovery Prevention: 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 Algorithms Now 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 Methods The different types of stenographic techniques available are: 1. Pure Steganography 2. Public key Steganography 3. Secret key Steganography Pure 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 the

Message if the unauthorized person knows the embedding method. It has one advantage that it reduces the difficulty in key sharing.

Figure 7. Pure Steganography process

Secret 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 p ublic database

Figure 9. Public key Steganography Process

We 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 Algorithms In 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: The P versus NP problem is a major unsolved 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 by Stephen Cook in 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 term quickly used above means the existence of an algorithm for the task that runs in polynomial time. The general class of questions for which some algorithm can provide an answer in polynomial time is called "class P" 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 be verified in polynomial time is called NP. Consider the subset 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 nonempty subset of 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, in exponential time, which consists of 2n-1 tries), and indeed such an algorithm can only exist if P = NP; hence this problem is in NP (quickly checkable) but not necessarily in P (quickly solvable). An answer to the P = NP question 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 that P NP, it would mean that there are problems in NP (such as NP-complete problems) 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 class P consists of all those decision problems (defined below) that can be solved on a deterministic sequential machine in an amount of time that is polynomial in the size of the input; the class NP consists of all those decision

problems whose positive solutions can be verified in polynomial time given the right information, or equivalently, whose solution can be found in polynomial time on a non-deterministic machine. Clearly, P NP. 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 the complexity classes P and NP is studied in computational complexity theory, the part of the theory of computation dealing 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 Algorithm Below 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)<=(2^n)/2 then no adjustment is made in that pixel. Else Step6: If (d1<d2) d = d 2^n. If (d1>d2) d = d + 2^n. Thisd is converted to binary and written back to pixel. This method of substitution is simple and easy to retrieve the data and the image quality better so that it provides good security. The encoder algorithm is as given below: 1: for i = 1... len(msg) do 2: p = LSB (pixel of the image) 3: if p != message bit then 4: pixel of the image = message bit 5: end if 6: end for

The encoding process shows that the entire algorithm can be implemented by writing just a few lines of code. The algorithm works by taking the first pixel of the image and obtaining its LSB value (as per line 2 of the Algorithm). This is typically achieved by calculating the modulus 2 of the pixel value. This will return a 0 if the number is even, and a 1 if the number is odd, which effectively tells us the LSB value. We then compare this value with the message bit that we are trying to embed. If they are already the same, then we do nothing, but if they are different then we replace the pixel value with the message bit. This process continues whilst there are still values in the message that need to be encoded The decoder algorithm is: 1: for i = 1, ..., len(image string) do 2: message string = LSB (pixel string of the image) 3: end for The decoding phase is even simpler. As the encoder replaced the LSBs of the pixel values in c in sequence, we already know the order that should be used to retrieve the data. Therefore all we need to do is calculate the modulus 2 of all the pixel values in the stegogramme, and we are able to reconstruct m as m0 .The above Algorithm shows the pseudo code of the decoding process. Note that this time we run the loop for length of message instead of length of string. This is because the decoding process is completely separate from the encoding process and therefore has no means of knowing the length of the message. If a key were used, it would probably reveal this information, but instead we simply retrieve the LSB value of every pixel. When we convert this to ASCII, the message will be readable up to the

point that the message was encoded, and will then appear as gibberish when we are reading the LSBs of the image data. Hide & Seek: The randomized approach to the Hide & Seek algorithm makes it possible to scatter the locations of the pixels that are to be replaced with the message data. The core of the encoding process is identical to that of the LSB algorithm described above. In fact, the two methods only differ in terms of how the image data is presented before the embedding process starts. For the randomized approach the image data c is usually shuffled using a Pseudo Random Number Generator (PRNG). This generator will take the image data and produce a shuffled version C according to a seed k that is specified by the encoder. There will also be an inverse shuffle which takes C and returns the original order c when the same k is used. The pixel values of the image c are often shuffled before embedding such that the exact same encoding mechanism from above algorithm can be used. The values are then shuffled back to their original positions after embedding such that the image can be displayed properly for sending it across some communications channel to the recipient. A PRNG also has the advantage that it produces the same shuffle when the same data and the same seed are given back to it. This means that all we need is c and k at the decoding stage, and the same shuffle will be recreated so we can retrieve the message data successfully. The encoding algorithm below shows the pseudo code for the encoding process of the randomized Hide & Seek approach. Now we have line 1 that randomizes the locations of each pixel before embedding the message data. In addition to this, we also have line 8 which returns the pixel locations back to normal when the

embedding process has ended. The seed k acts as a key to the algorithm such that the same shuffle sequence can be generated when retrieving the hidden message. The output stegogramme s from this embedding approach will contain bits of the hidden message in seemingly random locations of the image. The encoding algorithm: 1: generate randomized sequence C using data c and seed k 2: for i = 1, ..., l(m) do 3: p == LSB(Ci) 4: if p != message bit then 5: ci == mi 6: end if 7: end for 8: generate original sequence c using data C and seed k Perhaps the most important aspect of note is that as we require k to identify the correct regions, the algorithm is much more secure than the sequential approach, as the sequence cannot be derived without it. The decoding algorithm: 1: generate randomized sequence S using data s and seed k 2: for i = 1, ..., l(s) do 3: mi == LSB(Si)

4: end for Sometimes, as a seed is already required to retrieve the message, the randomizes approaches may go one step further and create a full key that also declares l(m). If this is the case, line 2 can be changed such that the loop runs for l(m) rather than l(s). JSTEG algorithm: JSteg algorithm is one of the stenographic techniques for embedding data into JPEG images. The hiding process will be done by replacing Least Significant Bits (LSB). JSteg algorithm replaces LSBs of quantized Discrete Courier Transform (DCT) coefficients. In fact, the JSteg algorithm only differs from the Hide & Seek algorithm because it embeds the message data within the LSBs of the DCT coefficients of c, rather than its pixel values. Before the embedding process begins, the image is converted to the DCT domain in 8x8 blocks such that the values of ci switch from pixel values to DCT coefficients. In order for the values to be presented as whole numbers, each 8x8 block is quantized according to a Quantization Table Q. The result is where the embedding algorithm operates. An example of an 8x8 DCT block is shown in Figure 10. In this process the hiding mechanism skips all coefficients with the values of 0 or 1. This algorithm is resistant to visual attacks and offers an admirable capacity for stenographic messages. It has high capacity and had a compression ratio of 12%. JSteg algorithm is restricted for visual attacks and it is less immune for statistical attacks. Normally, JSteg embeds only in BMP images.

In these BMP images, the content of the image is transformed into frequency coefficients so as to achieve storage in a very compressed format. There is no visual attack in the sense presented here, due to the influence of one stenographic bit up to 256 pixels.

Figure 10. An example of an 8x8 sub-block of DCT coefficients

We should also note the two types of coefficient that we see in every 8x8 block: DC, and AC. The value at the top left of each 8x8 block is known as the DC coefficient. It contains the mean value of all the other coefficients in the block, referred to as the AC coefficients. The DC coefficients are highly important to each block as they give a good estimate as to the level of detail in the block. Changing the value of the DC coefficient will also change many of the values of the AC coefficients, and this will create a visual discrepancy when the image is converted back to the spatial domain and viewed normally. For this reason, the

JSteg algorithm does not embed message data over any of the DC coefficients for every block. In addition to this, the algorithm also does not permit embedding on any AC coefficient equal to 0 or 1. The encoding algorithm 1: convert image c to DCT domain d in 8x8 blocks 2: for i = 1, ..., l(m) do 3: p == DCT(di) 4: while p = DC or p = 0 or p = 1 do 5: p = next DCT coefficient from d 6: end while 7: pi == ci mod 2 + mi 8: ci == pi 9: end for 10: convert each 8x8 block back to spatial domain The above algorithm provides the pseudo code for the encoding process of the JSteg algorithm. Line 4 shows that the algorithm avoids embedding on the DC coefficients, and also any AC coefficient equal to 0 or 1. Line 8 shows an alternative method for calculating the LSB value of the coefficient by using mod 2. The result is replaced with the value in mi. Again, no key is used for this algorithm. So long as the decoder knows that the embedding took place in the DCT domain, it will be capable of extracting the message successfully. The security of the JSteg algorithm therefore lies in the algorithm itself. As we noted before, the

main difficulty of not using a key is when we try to determine l(s) when extracting the message. Without a key, it is impossible to know the length of the message to extract, so the loop is typically run for the entire duration of the image to ensure that the entire message is extracted. This is certainly the case for the JSteg algorithm as we will see in the decoding process. The decoder algorithm 1: convert image s to DCT domain d in 8x8 blocks 2: for i = 1, ..., l(s) do 3: p == DCT(di) 4: while p = DC or p = 0 or p = 1 do 5: p = next DCT coefficient from d 6: end while 7: mi == di mod 2 8: end for The decoding process functions by converting the stegogramme s to the DCT domain. It then avoids the same coefficient values that the encoding algorithm avoids, and retrieves the hidden message from the LSBs of all the other coefficients sequentially (line 7). The performance of the algorithms differs with the type of cover image or source on which the data is embedded. The comparison of these algorithms is tabulated below:

Stenographic algorithm NP Hard and NP High Complete LSB F5 JSteg High Low

Speed

Quality of hiding

Security

Good

Strong

Good Medium Embedding capacity up to 12%

Medium Medium Less

Moderate

1.3.4 Cryptographic Algorithms The word cryptography is derived from two Greek words which mean secret writing. Cryptography is the process of scrambling the original text by rearranging and substituting the original text, arranging it in a seemingly unreadable format for others. Cryptography is an effective way to protect the information that is transmitting through the network communication paths. Cryptology is the science that deals about cryptography and cryptanalysis. Cryptography is the approach of sending the messages secretly and securely to the destination. Cryptanalysis is the method of obtaining the embedded messages into original texts. In general, cryptography is transferring data from source to destination by altering it through a secret code. The cryptosystems uses a plaintext as an input and generate a cipher text using encryption algorithm taking secret key as input. The important elements in cryptosystems are:

Plain text: The plain text is an original piece of information that is needed to send information to the destination. Encryption algorithm: This is the main key to any cryptographic system. This encryption algorithm subjects the plain text to various substitutions and transformations. Secret key: The secret key is given by the user which will act as an input to the encryption algorithm. Based on this key, various substitutions and transformations on the plain text will differ. Cipher text: This is the output generated by the encryption algorithm. The cipher text is the jumbled text. The cipher text differs with each and every secret key that has given to the encryption algorithm. Decryption algorithm: This is opposite to the encryption algorithm. It will acquire cipher text and secret key as an input and produce plain text as an output. We know that cryptography can be used in conjunction with steganography. As such we have used two cryptographic algorithms to use in our project. Both are symmetric key algorithms and the keys are fixed by us to reduce the simplicity of the project.

Figure 10. General model of cryptographic algorithm

In our application when the user enters the text to be hidden, it is passed through these encryption algorithms first and then it is passed through the Stenographic algorithm which the user selected. The encryption algorithms are used in the hope that even if someone uses Steganalysis and discovers the algorithm we are using to perform steganography, he will still not be able to gain anything since the message will be encrypted. We have developed two algorithms to be used with our project which are both simple and efficient. Also we have used the XOR method to combine the encrypted text with the encrypted password which is then embedded into the message. These algorithms together with the XOR method are described in details below.

Algorithm 1 This algorithm was written and coded by us specifically for this project. The main advantage of this algorithm is that it provides the encrypted text the same size as the clear text. The pseudo code of the algorithm is given below: The encryption algorithm: Step 1: Generate the ASCII value of the letter Step 2: Generate the corresponding binary value of it. [Binary value should be 8 digits e.g. for decimal 32 binary number should be 00100000] Step 3: Reverse the 8 digits binary number Step 4: Take a 4 digits divisor (>=1000) as the Key Step 5: Divide the reversed number with the divisor Step 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 Key Step 2: Add first 3 digits of the cipher text with the result produced in the previous step Step 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 be 01010100 Step 3: Reverse of this binary number would be 0 0 1 0 1 0 1 0 Step 4: Let 1000 as divisor i.e. Key Step 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 0 Step 2: After adding 010 (first 3 digits of the ciphertext) with 101000 the result would be 1 0 1 0 1 0

Step 3: Since 101010 is not an 8-bit number we need to make it 0 0 1 0 1 0 1 0 Step 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 0 Algorithm 2 Apart 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 ol Algorithm 3 After 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 project 1. Confidential communication and secret data storing 2. Protection of data alteration 3. Access control system for digital content distribution 1.5 Proposed Solution Strategy We 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 2 SOFTWARE REQUIREMENT SPECIFICATION DOCUMENT (SRS)

2.1 Introduction 2.1.1 Purpose We 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 Definitions All the definitions are explained in Appendix A. 2.2 Overall Description 2.2.1 Product Function There 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 Characteristics Any user with a little knowledge of computers and security will be able to operate our application. 2.2.3 Dependencies The 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 Requirements 2.3.1 Use Case Diagram
EMPORT A FILE FOR A ENCRYPTION

EMPORT A FILE FOR DESCRPTION

ENTER TEXT TO BE EMBEDDED

PERFORMANCE ENCRYPTION/ DECREPTION

GE

CHOOSE BETWEEN BASIC AND ADVANCED VIEW SAVE DECRPTED TEXT IN A TEXT FILE

CHOOSE THE STENOGRAPHY ALGORITHM GENERAL USER

EXIT THE APPLICATION

HIDE THE SECRET

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 Requirements A 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 Requirements 2.4.1 Performance The embedded image generated should not contain any distortion. Also the application should be secure to statistical and comparison steganalysis. 2.4.2 Reliability The 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 Portability Our 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 Diagrams Data 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 Diagram DFD 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.

0.0 Source Personal Data

Destination

Figure 11. Level 0 Data Flow Diagram

DFD 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 Diagram

1.0 Encrypted Phase

0.0 Secret Data

2.0 Transmission Phase

3.0 Description Phase

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 Diagram The 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.
2.0 Transmission 3.0 Description

1.0 Encryption

Encryption Decryption Algorithm Algorithm

Career Image

Plane Text

Plain Text

Figure 13. Level 2 Data Flow Diagram

2.6 Activity Diagram

Sender

(Image, Text File)

Carrier Image

Encryption Algorithm

Plain Text

Decryption Algorithm

Stenography Module

Receiver

Figure 14. Activity Diagram

The 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 text from the image so that the decryption phases generate plain text. The plain text is then sent to the receiver using the transmission media.

CHAPTER 3 DESIGN STRATEGY 3.1 Overview The 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 endproduct 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 & Considerations The 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 Tools We 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 Basic Visual 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 method In 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: 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. 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. described above. It requires the user to provide a correct password and the data in the image will decrypted.

3.6 Interface Screenshots The 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 interface Browse 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 4 SOFTWARE TESTING 4.1 Introduction Testing 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 Testing The 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 Cases Tests 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 5 RESULTS AND CONCLUSION 5.1 Result The 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 Conclusion In 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 Work The 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. AddisonWesley, 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. AddisonWesley, 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 I SOURCE CODE For browse an image and file


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 Encryption
using using using using System; System.Drawing; System.Windows.Forms; 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 < for (j (width / 3) * 3) / 3 { if { height && i * (height / 3) < fSize + fNameSize; i++) = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < (height * 1 && i * (height / 3) + (j / 3) < fSize + fNameSize; j++) (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<=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); 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 Decryption
using using using using System; System.Drawing; System.Windows.Forms; 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 < for (j (width / 3) * 3) / 3 { if { height && i * (height / 3) < fSize + fNameSize; i++) = 0; j < (width / 3) * 3 && i * (height / 3) + (j / 3) < (height * 1 && i * (height / 3) + (j / 3) < fSize + fNameSize; j++) (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<=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); 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"); } } }

You might also like