Professional Documents
Culture Documents
ON
“IMAGE STEGANOGRAPHY”
BACHELOR IN ENGINEERING
IN
This is to certify that the following students of CSE (7 th sem) have completed the work on
project entitled “IMAGE STEGANOGRAPHY”
Project Guide
The External Viva-Voice has been taken and the project report has been found to be
satisfactory.
External Examiner
ACKNOWLEDGEMENT
We would like to express our deep-felt gratitude to our Project Guide, xxx for giving us
an opportunity to work and for her advice, encouragement, and constant support. We
wish to thank her for extending us the greatest freedom in deciding the direction and
scope of our project. It has been both a privilege and a rewarding experience working
with her.
We would also like to thank our colleagues here at UIET for all the wonderful times we
have had with them. Their valuable comments and suggestions have been vital to the
completion of this work. We want to thank the faculty of UIET and the staff for
providing us the means to complete our degree.
And finally, we are grateful to our parents and siblings for their love, understanding,
encouragement and support.
TABLE OF CONTENTS
ABSTRACT…………………………………………………………….........
1) INTRODUCTION
1.1) INTRODUCTION…………………………………………………………………………………...........
1.9) IMPLEMENTATION………………………………………………………………………………….....
2) PROJECT OVERVIEW
2.1) PROJECT DESCRIPTION…..…………………………………………………………………………...
2.2.2.1) C#.NET/C++..…………………………………………………………………………………....
2.5) SCOPE…..…………………………………………………………………………………………….......
3) PROJECT DESIGN
3.1) WBS Diagram…..………………………………………………………………………………….....
4) PROJECT IMPLEMENTATION
4.1) Coding….....………………………………………………………………………………………........
4.2) Snapshots…......………………………………………………………………………………………..
4.3) Testing…..……....…………………………………………………………………………….............
6) CONCLUSION
BIBLIOGRAPHY…………………………………………………………...
INTRODUCTION
1.1) INTRODUCTION
One of the reasons that intruders can be successful is that most of the information they
acquire from a system is in a form that they can read and comprehend. Intruders may
reveal the information to others, modify it to misrepresent an individual or organization,
or use it to launch an attack. One solution to this problem is, through the use of
steganography. Steganography is a technique of hiding information in digital media. In
contrast to cryptography, it is not to keep others from knowing the hidden information
but it is to keep others from thinking that the information even exists.
Steganography is the art of hiding the fact that communication is taking place, by hiding
information in other information. Many different carrier file formats can be used, but
digital images are the most popular because of their frequency on the Internet. For hiding
secret information in images, there exists a large variety of steganographic techniques
some are more complex than others and all of them have respective strong and weak
points. Different applications have different requirements of the steganography technique
used. For example, some applications may require absolute invisibility of the secret
information, while others require a larger secret message to be hidden. This project
intends to give an overview of image steganography, its uses and techniques. It also
attempts to identify the requirements of a good steganographic algorithm and briefly
reflects on which steganographic techniques are more suitable for which applications.
Basically, the model for steganography is shown in Figure 1. Message is the data that the
sender wishes to remain it confidential. It can be plain text, ciphertext, other image, or
anything that can be embedded in a bit stream such as a copyright mark, a covert
communication, or a serial number. Password is known as stego-key, which ensures that
only recipient who knows the corresponding decoding key will be able to extract the
message from a cover-object. The cover-object with the secretly embedded message is
then called the stego-object.
In general, the information hiding process extracts redundant bits from cover-object. The
process consists of two steps:
Identification of redundant bits in a cover-object. Redundant bits are those bits that can
be modified without corrupting the quality or destroying the integrity of the cover object.
The embedding process then selects the subset of the redundant bits to be replaced with
data from a secret message. The stego-object is created by replacing the selected
redundant bits with message bits.
In contras, steganography does not alter the structure of the secret message, but hides it
inside a cover-image so it cannot be seen. A message in cipher text, for instance, might
arouse suspicion on the part of the recipient while an “invisible” message created with
steganographic methods will not. In other word, steganography prevents an unintended
recipient from suspecting that the data exists. In addition, the security of classical
steganography system relies on secrecy of the data encoding system. Once the encoding
system is known, the steganography system is defeated.
In ancient Greece, messages were hidden on the back of wax writing tables where
someone would peel off the wax that was or written on the stomachs of rabbits.
In Ancient Greece they used to select messengers and shave their head, they would then
write a message on their head. Once the message had been written the hair was allowed
to grow back. After the hair grew back the messenger was sent to deliver the message, the
recipient would shave off the messengers hair to see the secrete message.
During World War 2 invisible ink was used to write information on pieces of paper so
that the paper appeared to the average person as just being blank pieces of paper. Liquids
such as milk, vinegar and fruit juices were used, because when each one of these
substances were heated they darken and become visible to the human eye. Invisible ink
has been in use for centuries—for fun by children and students and for serious espionage
by spies and terrorists.
Cryptography became very common place in the middle ages. Secret writing was
employed by the Catholic Church in its various struggles down the ages and by the major
governments of the time. Steganography was normally used in conjunction with
cryptography to further hide secret information.
According to research the human eye is more sensitive to changes in the brightness
(luminance) of a pixel than to changes in its color. This fact is exploited by the JPEG
compression by down-sampling the color data to reduce the size of the file. The color
components (U and V) are halved in horizontal and vertical directions, thus decreasing
the file size by a factor of 2. The next step is the actual transformation of the image. For
JPEG, the Discrete Cosine Transform (DCT) is used, but similar transforms are for
example the Discrete Fourier Transform (DFT). These mathematical transforms convert
the pixels in such a way as to give the effect of “spreading” the location of the pixel
values over part of the image. The DCT transforms a signal from an image representation
into a frequency representation, by grouping the pixels into 8 × 8 pixel blocks and
transforming the pixel blocks into 64 DCT coefficients each. A modification of a single
DCT coefficient will affect all 64 image pixels in that block. The next step is the
quantization phase of the compression. Here another biological property of the human
eye is exploited: The human eye is fairly good at spotting small differences in brightness
over a relatively large area, but not so good as to distinguish between different strengths
in high frequency brightness. This means that the strength of higher frequencies can be
diminished, without changing the appearance of the image. JPEG does this by dividing
all the values in a block by a quantization coefficient. The results are rounded to integer
values and the coefficients are encoded using Huffman coding to further reduce the size.
JPEG steganography
Originally it was thought that steganography would not be possible to use with JPEG
images, since they use lossy compression which results in parts of the image data being
altered. One of the major characteristics of steganography is the fact that information is
hidden in the redundant bits of an object and since redundant bits are left out when using
JPEG it was feared that the hidden message would be destroyed. Even if one could
somehow keep the message intact it would be difficult to embed the message without the
changes being noticeable because of the harsh compression applied. However, properties
of the compression algorithm have been exploited in order to develop a steganographic
algorithm for JPEGs.
One of these properties of JPEG is exploited to make the changes to the image invisible
to the human eye.
During the DCT transformation phase of the compression algorithm, rounding errors
occur in the coefficient data that are not noticeable. Although this property is what
classifies the algorithm as being lossy, this property can also be used to hide messages. It
is neither feasible nor possible to embed information in an image that uses lossy
compression, since the compression would destroy all information in the process. Thus it
is important to recognize that the JPEG compression algorithm is actually divided into
lossy and lossless stages. The DCT and the quantization phase form part of the lossy
stage, while the Huffman encoding used to further compress the data is lossless.
Steganography can take place between these two stages. Using the same principles of
LSB insertion the message can be embedded into the least significant bits of the
coefficients before applying the Huffman encoding. By embedding the information at this
stage, in the transform domain, it is extremely difficult to detect, since it is not in the
visual domain.
The levels at which the algorithms satisfy the requirements are defined as high, medium
and low. A high level means that the algorithm completely satisfies the requirement,
while a low level indicates that the algorithm has a weakness in this requirement. A
medium level indicates that the requirement depends on outside influences, for example
the cover image used. LSB in GIF images has the potential of hiding a large message, but
only when the most suitable cover image has been chosen.
The ideal, in other words a perfect steganographic algorithm would have a high level in
every requirement. Unfortunately its hard to develop an algorithm that satisfies all of the
requirements. Thus a trade-off will exist in most cases, depending on which requirements
are more important for the specific application.
1.9) IMPLEMENTATION
There are currently three effective methods in applying Image Steganography in spatial
domain:
LSB Substitution
Blocking (DCT)
Palette Modification.
LSB (Least Significant Bit) Substitution is the process of modifying the least significant
bit of the pixels of the carrier image.
Blocking works by breaking up an image into “blocks” and using Discrete Cosine
Transforms (DCT). Each block is broken into 64 DCT coefficients that approximate
luminance and color—the values of which are modified for hiding messages.
Palette Modification replaces the unused colors within an image’s color palette with
colors that represent the hidden message.
PROJECT OVERVIEW
Visual Studio 2010, .NET Framework 4.0 and Adobe Photoshop CS5 installed on the
system.
SOFTWARE DESCRIPTION
C# is a relatively new language that was unveiled to the world when Microsoft announced the
first version of its .NET Framework in July 2000. Since then its popularity has rocketed, and it
has arguably become the language of choice for both Windows and Web developers who use
the .NET Framework. Part of the appeal of C# comes from its clear syntax, which derives from
C/C++ but simplifies some things that have previously discouraged some programmers.
Despite this simplification, C# has retained the power of C++, and there is now no reason not
to move into C#. The language is not difficult and it’s a great one to learn elementary
programming techniques with.
.
By design, C# is the programming language that most directly reflects the underlying
Common Language Infrastructure (CLI). Most of its intrinsic types correspond to value-
types implemented by the CLI framework. However, the language specification does not
state the code generation requirements of the compiler: that is, it does not state that a C#
compiler must target a Common Language Runtime, or generate Common Intermediate
Language (CIL), or generate any other specific format. Theoretically, a C# compiler
could generate machine code like traditional compilers of C++ or Fortran.
There are no global variables or functions. All methods and members must be
declared within classes. Static members of public classes can substitute for global
variables and functions.
Local variables cannot shadow variables of the enclosing block, unlike C and C++.
Variable shadowing is often considered confusing by C++ texts.
C# supports a strict Boolean datatype, bool. Statements that take conditions, such as
while and if, require an expression of a type that implements the true operator,
such as the boolean type. While C++ also has a boolean type, it can be freely
converted to and from integers, and expressions such as if(a) require only that a is
convertible to bool, allowing a to be an int, or a pointer. C# disallows this "integer
meaning true or false" approach on the grounds that forcing programmers to use
expressions that return exactly bool can prevent certain types of common
programming mistakes in C or C++ such as if (a = b) (use of assignment = instead
of equality ==).
In C#, memory address pointers can only be used within blocks specifically marked
as unsafe, and programs with unsafe code need appropriate permissions to run.
Most object access is done through safe object references, which always either
point to a "live" object or have the well-defined null value; it is impossible to
obtain a reference to a "dead" object (one which has been garbage collected), or to
a random block of memory. An unsafe pointer can point to an instance of a value-
type, array, string, or a block of memory allocated on a stack. Code that is not
marked as unsafe can still store and manipulate pointers through the System.IntPtr
type, but it cannot dereference them.
Multiple inheritance is not supported, although a class can implement any number of
interfaces. This was a design decision by the language's lead architect to avoid
complication and simplify architectural requirements throughout CLI.
C# is more type safe than C++. The only implicit conversions by default are those
which are considered safe, such as widening of integers. This is enforced at
compile-time, during JIT, and, in some cases, at runtime. There are no implicit
conversions between booleans and integers, nor between enumeration members
and integers (except for literal 0, which can be implicitly converted to any
enumerated type). Any user-defined conversion must be explicitly marked as
explicit or implicit, unlike C++ copy constructors and conversion operators,
which are both implicit by default.
Checked exceptions are not present in C# (in contrast to Java). This has been a
conscious decision based on the issues of scalability and versionability.
Technical Feasibility
Image Steganography is a defence application with a back-end coding done in C#.NET
that allows a user to hide data (documents or text files) in an image. The user friendly
interface requires no technical skills and is easy to operate on. Visual Studio 2010
using .NET 4.0 framework is used for the design and coding purposes. Adobe Photoshop
CS5 has also been used to design the header of the application with an animated sequence
of images.
Economic Feasibility
The project is economic and highly beneficial project as far as the cost of development is
considered. No extra costs were incurred apart from the software used.
Operational Feasibility
The project is operationally very feasible as it is user-friendly, the user doesn’t need any
kind of knowledge about the software used in the project. The project is also really
helpful as the user can use it to send encrypted data at any moment of time using the
2.4) OBJECTIVE
This project comprehends the following objectives:
To produce security tool based on steganographic techniques.
To explore LSB techniques of hiding data using steganography.
2.5) SCOPE
The scope of the project as follows:
Implementation of a variation of LSB technique for hiding information i.e. text in image
files.
2.6) IMAGE DEFINITION
To a computer, an image is a collection of numbers that constitute different light
intensities in different areas of the image. This numeric representation forms a grid and
the individual points are referred to as pixels. Most images on the Internet consists of a
rectangular map of the image’s pixels (represented as bits) where each pixel is located
and its color. These pixels are displayed horizontally row by row. The number of bits in a
color scheme, called the bit depth, refers to the number of bits used for each pixel.
The smallest bit depth in current color schemes is 8, meaning that there are 8 bits used to
describe the color of each pixel. Monochrome and greyscale images use 8 bits for each
pixel and are able to display 256 different colors or shades of grey. Digital color images
are typically stored in 24-bit files and use the RGB color model, also known as true color.
All color variations for the pixels of a 24-bit image are derived from three primary colors:
red, green and blue, and each primary color is represented by 8 bits. Thus in one given
pixel, there can be 256 different quantities of red, green and blue, adding up to more than
16-million combinations, resulting in more than 16-million colors. Not surprisingly the
larger amount of colors that can be displayed, the larger the file size. For this project, we
are considering 8-bit images.
2.7) IMAGE COMPRESSION
When working with larger images of greater bit depth, the images tend to become too
large to transmit over a standard Internet connection. In order to display an image in a
reasonable amount of time, techniques must be incorporated to reduce the image’s file
size. These techniques make use of mathematical formulas to analyse and condense
image data, resulting in smaller file sizes. This process is called compression. In images
there are two types of compression: lossy and lossless. Both methods save storage space,
but the procedures that they implement differ. Lossy compression creates smaller files by
discarding excess image data from the original image. It removes details that are too
small for the human eye to differentiate, resulting in close approximations of the original
image, although not an exact duplicate. An example of an image format that uses this
compression technique is JPEG (Joint Photographic Experts Group).
Lossless compression, on the other hand, never removes any information from the
original image, but instead represents data in mathematical formulas. The original
image’s integrity is maintained and the decompressed image output is bit-by-bit identical
to the original image input. The most popular image formats that use lossless
compression is GIF (Graphical Interchange Format) and 8-bit BMP (a Microsoft
Windows bitmap file).
Compression plays a very important role in choosing which steganographic algorithm to
use. Lossy compression techniques result in smaller image file sizes, but it increases the
possibility that the embedded message may be partly lost due to the fact that excess
image data will be removed. Lossless compression though, keeps the original digital
image intact without the chance of lost, although is does not compress the image to such
a small file size. Different steganographic algorithms have been developed for both of
these compression types and will be explained in the following sections.
2.8) LEAST SIGNIFICANT BIT
Least significant bit (LSB) insertion is a common, simple approach to embedding
information in a cover image. The least significant bit (in other words, the 8th bit) of
some or all of the bytes inside an image is changed to a bit of the secret message. When
using a 24-bit image, a bit of each of the red, green and blue color components can be
used, since they are each represented by a byte. In other words, one can store 3 bits in
each pixel. An 800 × 600 pixel image, can thus store a total amount of 1,440,000 bits or
180,000 bytes of embedded data. For example a grid for 3 pixels of a 24-bit image can be
as follows:
(00101101 00011100 11011100)
(10100110 11000100 00001100)
(11010010 10101101 01100011)
When the number 200, which binary representation is 11001000, is embedded into the
least significant bits of this part of the image, the resulting grid is as follows:
Although the number was embedded into the first 8 bytes of the grid, only the 3
underlined bits needed to be changed according to the embedded message. On average,
only half of the bits in an image will need to be modified to hide a secret message using
the maximum cover size. Since there are 256 possible intensities of each primary color,
changing the LSB of a pixel results in small changes in the intensity of the colors. These
changes cannot be perceived by the human eye - thus the message is successfully hidden.
With a well-chosen image, one can even hide the message in the least as well as second
to least significant bit and still not see the difference.
In the above example, consecutive bytes of the image data – from the first byte to the end
of the message – are used to embed the information. This approach is very easy to detect.
A slightly more secure system is for the sender and receiver to share a secret key that
specifies only certain pixels to be changed. Should an adversary suspect that LSB
steganography has been used, he has no way of knowing which pixels to target without
the secret key.
In its simplest form, LSB makes use of BMP images, since they use lossless
compression. Unfortunately to be able to hide a secret message inside a BMP file, one
would require a very large cover image. Nowadays, BMP images of 800 × 600 pixels are
not often used on the Internet and might arouse suspicion. For this reason, LSB
steganography has also been developed for use with other image file formats.
PROJECT DESIGN
3.1) WORK BREAKDOWN STRUCTURE
3.2) INTERFACE DESIGN
The interface is designed keeping the user in mind. There are two buttons on the left
panel, with one asking the user to load the file to be encrypted, and the other asking the
user to load the image in which the data is to be hidden. Only after the two files are
browsed, will the encryption start, or else it’ll give an error message asking the user to
load both the files. After the user clicks on the encryption button, the status bar at the
bottom of the application gives us the state of encryption and after the encryption is
complete, we get a message box stating the same. But before encryption is done, it’ll ask
the user to give the name by which the used would like to save the encrypted image
which should also necessarily be filled.
CHAPTER 4
PROJECT
IMPLEMETATION
4.1) Coding: The algorithm implementation of steganography in C# on Visual Studio.
4.2) SNAPSHOTS
4.3) Testing:
Functionality testing: testing if the end product is fully functional with all its
functionality intact.
Usability testing: testing if the application works fine with all its upload links and
buttons working.
Interface testing: testing if the interface is use friendly or not.
Compatibility testing: testing its compatibility with other systems or operating systems.
CHAPTER 5
PROJECT
AND
FUTURE SCOPE
5.1) PROJECT SCOPE
This application would enable defence personnels to send confidential data of high
priority to others. Because the human eye can not decipher that there is any encrypted
text, it can be put to great use while remaining easy to understand and use.
In today’s world, we often listen a popular term “Hacking”. Hacking is nothing but an
unauthorized access of data which can be collected at the time of data transmission. With
respect to steganography this problem is often taken as Steganalysis. Steganalysis is a
process in which a steganalyzer cracks the cover object to get the hidden data. So,
whatever be the technique will be developed in future, degree of security related with that
has to be kept in mind. It is hoped that Dual Steganography, Steganography along with
Cryptography may be some of the future solution for this above mentioned problem.
We hope to add support to hide all file formats. This allows for a much broader spectrum
of uses: one would be able to encode .gif, .png, .pdf, .mp3, etc. The program would be
more versatile because often hiding text just isn’t enough. We also would like to
implement batch image processing and statistical analysis so that we can run the program
through a dataset of images and detect Steganography and perhaps crawl through Google
Image Search to see how prevalent Steganography is. We eventually plan to port the
program to use C/C++ so that we may take advantage of bit-fields in C and learn to code
GUI’s as well. I have a plug-in handler developed for C++ that I would like to use in this
project so that third-party developers may contribute to the project.
CHAPTER 6
CONCLUSION
6.1) CONCLUSION
As steganography becomes more widely used in computing, there are issues that need to
be resolved. There are a wide variety of different techniques with their own advantages
and disadvantages. Many currently used techniques are not robust enough to prevent
detection and removal of embedded data. The use of benchmarking to evaluate
techniques should become more common and a more standard definition of robustness is
required to help overcome this. For a system to be considered robust it should have the
following properties:
The quality of the media should not noticeably degrade upon addition of a secret data.
Secret data should be undetectable without secret knowledge, typically the key.
If multiple data are present they should not interfere with each other.
The secret data should survive attacks that don’t degrade the perceived quality of the
work.
This work presents a scheme that can transmit large quantities of secret information and
provide secure communication between two communication parties. Both steganography
and cryptography can be woven into this scheme to make the detection more
complicated. Any kind of text data can be employed as secret msg. The secret message
employing the concept of steganography is sent over the network. In addition, the
proposed procedure is simple and easy to implement. Also, the developed system has
many practical, personal and militaristic applications for both point-to-point and point-to
multi- point communications.
BIBLIOGRAPHY
BIBLIOGRAPHY
http://www.engpaper.com/free-research-papers-steganography.htm
http://en.wikipedia.org/wiki/Steganography
www.ece.stevens-tech.edu/~mouli/lsbsteg.pdf
www.waset.org/journals/waset/v50/v50-74.pdf
mo.co.za/open/stegoverview.pdf
www.maths.nuigalway.ie/cstudents/mcomms/.../steganography.pdf
http://www.ijcaonline.org/archives/volume6/number2/1057-1378
ipublishing.co.in/jarvol1no12010/EIJAER1018.pdf
faculty.ksu.edu.sa/ghazy/Steg/References/ref26-2.pdf
www1.chapman.edu/~nabav100/.../ImageSteganography.pdf
Kesslet, Gary C. An Overview of Steganography for the Computer Forensics
Examiner, Burlington, 2004.
Hosmer, Chet. Discovering Hidden Evidence, Cortland, 2006.
N.F. Johnson, S. Jajodia, “Staganalysis: The Investigation of Hiding
Information”, IEEE, pp. 113-116, 1998.
N.F. Johnson & S. Jajodia, “Steganalysis of Images Created Using Current
Steganography Software”, in Proceeding for the Second Information Hiding
Workshop, Portland Oregon, USA, April 1998, pp. 273-289.
APPENDIX
(PROGRAM CODE)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Minor_Project
{
public partial class Steganography : Form
{
public Steganography()
{
InitializeComponent();
}
//public values:
string loadedTrueImagePath, loadedFilePath, saveToImage, DLoadImagePath,
DSaveFilePath;
int height, width;
long fileSize, fileNameSize;
Image loadedTrueImage, DecryptedImage, AfterEncryption;
Bitmap loadedTrueBitmap, DecryptedBitmap;
Rectangle previewImage = new Rectangle(370, 170, 400, 400);
bool canPaint = false, EncriptionDone = false;
byte[] fileContainer;
canPaint = true;
this.Invalidate();
}
}
changedBitmap.Save(saveToImage);
toolStripProgressBar1.Increment(100);
toolStripStatusLabel1.Text = "Encrypted image has been saved
successfully.";
MessageBox.Show("Encrypted image has been saved successfully!",
"Done!", MessageBoxButtons.OK, MessageBoxIcon.Information);
EncriptionDone = true;
AfterEncryption = Image.FromFile(saveToImage);
this.Invalidate();
}
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;
gb[4] = t[0];
gb[5] = t[1];
gb[6] = t[2];
gb[7] = t[3];
bb[5] = t[4];
bb[6] = t[5];
bb[7] = t[6];
rb[7] = t[7];
}
else if (gb[0] == true && gb[1] == true && gb[2] == true
&& bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true)
{
gb[5] = t[0];
gb[6] = t[1];
gb[7] = t[2];
bb[4] = t[3];
bb[5] = t[4];
bb[6] = t[5];
bb[7] = t[6];
rb[7] = t[7];
}
gb[4] = t[0];
gb[5] = t[1];
gb[6] = t[2];
gb[7] = t[3];
bb[5] = t[4];
bb[6] = t[5];
bb[7] = t[6];
rb[7] = t[7];
}
else if (gb[0] == true && gb[1] == true && gb[2] == true &&
bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true)
{
gb[5] = t[0];
gb[6] = t[1];
gb[7] = t[2];
bb[4] = t[3];
bb[5] = t[4];
bb[6] = t[5];
bb[7] = t[6];
rb[7] = t[7];
}
Color result = Color.FromArgb((int)bool2byte(rb), (int)bool2byte(gb),
(int)bool2byte(bb));
outputBitmap.SetPixel(j, i, result);
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;
}
t[0] = gb[4];
t[1] = gb[5];
t[2] = gb[6];
t[3] = gb[7];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
resFName += (char)temp;
}
else if (gb[0] == true && gb[1] == true && gb[2] == true &&
bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true)
{
t[0] = gb[5];
t[1] = gb[6];
t[2] = gb[7];
t[3] = bb[4];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
resFName += (char)temp;
}
}
t[0] = gb[4];
t[1] = gb[5];
t[2] = gb[6];
t[3] = gb[7];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
res[i * (height / 3) + j / 3 - fNameSize] = temp;
}
else if (gb[0] == true && gb[1] == true && gb[2] == true &&
bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true)
{
t[0] = gb[5];
t[1] = gb[6];
t[2] = gb[7];
t[3] = bb[4];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
res[i * (height / 3) + j / 3 - 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 (gb[0] == true && gb[1] == true && gb[2] == true &&
gb[3] == true && bb[0] == true && bb[1] == true && bb[2] == true)
{
t[0] = gb[4];
t[1] = gb[5];
t[2] = gb[6];
t[3] = gb[7];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
res[i * (height / 3) + j / 3 + (6 - layer) * ((height
* (width / 3) * 3) / 3 - 1) + readedOnL8] = temp;
}
else if (gb[0] == true && gb[1] == true && gb[2] == true
&& bb[0] == true && bb[1] == true && bb[2] == true && bb[3] == true)
{
t[0] = gb[5];
t[1] = gb[6];
t[2] = gb[7];
t[3] = bb[4];
t[4] = bb[5];
t[5] = bb[6];
t[6] = bb[7];
t[7] = rb[7];
temp = bool2byte(t);
res[i * (height / 3) + j / 3 + (6 - layer) * ((height
* (width / 3) * 3) / 3 - 1) + readedOnL8] = temp;
}
}
if (File.Exists(DSaveFilePath + "\\" + resFName))
{
MessageBox.Show("File \"" + resFName + "\" already exist please
choose another path to save file", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
else
File.WriteAllBytes(DSaveFilePath + "\\" + resFName, res);
toolStripStatusLabel1.Text = "Decrypted file has been successfully
saved.";
Application.DoEvents();
}
private void byte2bool(byte inp, ref bool[] outp)
{
if(inp>=0 && inp<=255)
for (short i = 7; i >= 0; i--)
{
if (inp % 2 == 1)
outp[i] = true;
else
outp[i] = false;
inp /= 2;
}
else
throw new Exception("Input number is illegal.");
}
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();
}
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;
}
}