Professional Documents
Culture Documents
Report Steganography
Report Steganography
ABSTRACT…………………………………………………………….........
1) INTRODUCTION
1.1) INTRODUCTION…………………………………………………………………………………...........
1.9) IMPLEMENTATION………………………………………………………………………………….....
2) PROJECT OVERVIEW
2.1) PROJECT DESCRIPTION…..…………………………………………………………………………...
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:
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.
The word “Steganography” technically means “covered or hidden writing”. Its ancient
origins can be traced back to 440 BC. Although the term steganography was only coined
at the end of the 15th century, the use of steganography dates back several millennia.
1. In ancient Greece, messages were hidden on the back of wax writing tables where
someone would peel off the wax that was or written on the stomachs of rabbits.
2. In Ancient Greece they used to select messengers and shave their head, they
would then write a message on their head. Once the message had been written the
hair was allowed to grow back. After the hair grew back the messenger was sent
to deliver the message, the recipient would shave off the messengers hair to see
the secrete message.
3. During World War 2 invisible ink was used to write information on pieces of
paper so that the paper appeared to the average person as just being blank pieces
of paper. Liquids such as milk, vinegar and fruit juices were used, because when
each one of these substances were heated they darken and become visible to the
human eye. Invisible ink has been in use for centuries—for fun by children and
students and for serious espionage by spies and terrorists.
4. Cryptography became very common place in the middle ages. Secret writing was
employed by the Catholic Church in its various struggles down the ages and by
the major governments of the time. Steganography was normally used in
conjunction with cryptography to further hide secret information.
1.4) STEGANOGRAPHY TYPES
The majority of today’s steganographic systems uses multimedia objects like image,
audio, video etc as cover media because people often transmit digital pictures over email
and other Internet communication. In modern approach, depending on the nature of cover
object, steganography can be divided into five types:
• Text Steganography
• Image Steganography
• Audio Steganography
• Video Steganography
• Protocol Steganography
So, in the modern age so many steganographic techniques have been designed which
work with the above concerned objects. More often in today’s security advancement, we
sometimes come across a combination of Cryptography and Steganography to achieve
data privacy over secrecy. Various software tools are also available in this regard.
1.5) IMAGE AND TRANSFORM DOMAIN
Image steganography techniques can be divided into two groups: those in the Image
Domain and those in the Transform Domain. Image – also known as spatial – domain
techniques embed messages in the intensity of the pixels directly, while for transform –
also known as frequency – domain, images are first transformed and then the message is
embedded in the image. Image domain techniques encompass bit-wise methods that
apply bit insertion and noise manipulation and are sometimes characterised as “simple
systems”. The image formats that are most suitable for image domain steganography are
lossless and the techniques are typically dependent on the image format. Steganography
in the transform domain involves the manipulation of algorithms and image transforms.
These methods hide messages in more significant areas of the cover image, making it
more robust. Many transform domain methods are independent of the image format and
the embedded message may survive conversion between lossy and lossless compression.
In the next sections steganographic algorithms will be explained in categories according
to image file formats and the domain in which they are performed.
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.6.1) EVALUATION OF DIFFERENT TECHNIQUES ACCORDING TO
TABLE-2
LSB in BMP – When embedding a message in a “raw” image, which has not
been changed with compression, such as a BMP, there exists a trade-off between
the invisibility of the message and the amount of information that can be
embedded. A BMP is capable of hiding quite a large message, but the fact that
more bits are altered results in a larger possibility that the altered bits can be seen
with the human eye. The main disadvantage regarding LSB in BMP images is
surely the suspicion that might arise from a very large BMP image being
transmitted between parties, since BMP is not widely used anymore.
Suggested applications: LSB in BMP is most suitable for applications where the focus is
on the amount of information to be transmitted and not on the secrecy of that information.
LSB in GIF – The strong and weak points regarding embedding information in
GIF images using LSB are more or less the same as those of using LSB with
BMP. The main difference is that since GIF images only have a bit depth of 8, the
amount of information that can be hidden is less than with BMP. GIF images are
especially vulnerable to statistical – or visual attacks – since the palette processing
that has to be done leaves a very definite signature on the image. This approach is
dependent on the file format as well as the image itself, since a wrong choice of
image can result in the message being visible.
Suggested applications: LSB in GIF is a very efficient algorithm to use when
embedding a reasonable amount of data in a greyscale image.
JPEG compression – The process of embedding information during JPEG
compression results in a stego image with a high level of invisibility, since the
embedding takes place in the transform domain. JPEG is the most popular image
file format on the Internet and the image sizes are small because of the
compression, thus making it the least suspicious algorithm to use. However, the
process of the compression is a very mathematical process, making it more
difficult to implement.
Suggested applications: The JPEG file format can be used for most applications of
steganography, but is especially suitable for images that have to be communicated over
an open systems environment like the Internet.
Patchwork – The biggest disadvantage of the patchwork approach is the small
amount of information that can be hidden in one image. This property can be
changed to accommodate more information but one may have to sacrifice the
secrecy of the information. Patchwork’s main advantage, however, is its
robustness against malicious or unintentional image manipulation. Should a stego
image using patchwork be cropped or rotated, some of the message data may be
lost but since the message is repeatedly embedded in the image, most of the
information will survive.
Suggested applications: Patchwork is most suitable for transmitting a small amount of
very sensitive information.
Spread spectrum – Spread spectrum techniques satisfies most requirements and
is especially robust against statistical attacks, since the hidden information is
scattered throughout the image, while not changing the statistical properties.
Suggested applications: Spread spectrum techniques can be used for most
steganography applications, although its highly mathematical and intricate approach may
prove too much for some.
1.7) IMAGE STEGANOGRAPHY TECHNIQUES
To hide information, straight message insertion may encode every bit of information in
the image or selectively embed the message in “noisy” areas that draw less attention-
those areas where there is a great deal of natural color variation. The message may also
be scattered randomly throughout the image. A number of ways exist to hide information
in digital media. Common techniques which with varying degrees of success include:
1. Least significant bit insertion
2. Masking and filtering
3. Redundant Pattern Encoding
4. Encrypt and Scatter
5. Algorithms and transformations
PROJECT OVERVIEW
2.1) PROJECT DESCRIPTION
There are two trends at the time to implement steganographic algorithms: the methods
that work in the spatial domain (altering the desired characteristics on the file itself) and
the methods that work in the transform domain (performing a series of changes to the
cover image before hiding information. To select the best areas the Discrete Cosine
Transform DCT, Wavelet Transform, etc. are used).
While the algorithms that work in the transform domain are more robust, that is, more
resistant to attacks, the algorithms that work in the spatial domain are simpler and faster.
The best known steganographic method that works in the spatial domain is the LSB
(Least Significant Bit), which replaces the least significant bits of pixels selected to hide
the information. This method has several implementation versions that improve the
algorithm in certain aspects.
We have chosen to implement LSB Substitution in our project because of its ubiquity
among carrier formats and message types. With LSB Substitution, we could easily
change from Image Steganography to Audio Steganography and hide a zip archive
instead of a text message. LSB Substitution lends itself to become a very powerful
Steganographic method with few limitations. LSB Substitution works by iterating
through the pixels of an image and extracting the ARGB values. It then separates the
color channels and gets the least significant bit. Meanwhile, it also iterates through the
characters of the message setting the bit to its corresponding binary value.
Visual Studio 2010, .NET Framework 4.0 and Adobe Photoshop CS5 installed on the
system.
SOFTWARE DESCRIPTION
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;
}
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;
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();
}
}