Is a picture worth or contains more than a thousand words? — Steganography

D2Relz
6 min readMar 19, 2020

--

Hands-on LSB technique

1. Digital Image

An image is described from a visual representation of something or some form in which it is desired to replicate, be it abstract or concrete, however, this concept could not be easily applied without development in the area of science, precisely in astronomy, what caused the practicality in which digital images can be obtained today.

[1] define a digital image as a two-dimensional function F(x, y), where the level of gray or intensity at each point is determined by the amplitude of F in any pair of spatial coordinates (x, y). When the intensity values ​​of F in the coordinates (x, y) have finite and discrete quantities, the images are called digital. An example of a digital image can be seen in Figure 1.

Figure 1 (Digital image) — Author.

Basically, the images are matrices, where the image is described by the function F(x, y), the coordinates being integer values ​​where each point of an image has a specific location and value, called Picture Element (pixel).

The size that an image occupies on disk is proportional to the number of bits that each pixel has, which in turn, is related to the color system that the image uses. Some available models are: Shades of Gray (1bit), Red-Green-Blue (RGB) (3bit), Cyan-Magenta-Yellow-blacK (CMYK) (4bit). Thus, we define:

Size = Width * Heigth * Depth * BytesPerComponent

2. Terminology and aspects of steganography

In a nutshell, steganography is known as a method of hiding information
(independent of the information) leaving it unintelligible.

Even though the term steganography was only used in the late 15th century, the the use of steganography goes back several millennia. In ancient times, messages were hidden in the back of the wax, writing tables, written on rabbit stomachs, or tattooed on the scalp of slaves. Invisible paint has been used for centuries to amuse children or students and for espionage by spies and terrorists. Microdots, microfilm, staple of war and espionage films, emerged after the invention of photography[2][3][4].

3. How it Works?

In a simple way, Figure 2, the use of steganography is when you want to hide some information, such as a message, also called embedded data.

Figure 2 (One-on-One) — Author.

The most common steganography techniques are:

  1. Least Significant Bit (LSB): The technique addresses the replacement of the least significant bits of the image with data to be hidden;

This technique is the most used when it comes to steganography, LSB is a technique insertion of information in the least significant bit. According to [2] the least significant is the rightmost of each binary chain, which makes this technique viable, since, when inverted the value produces minimal changes being imperceptible for human vision (Figure 3). However, one of the disadvantages is image compression, only works on formats without loss of data (lossless).

Figure 3 (LSB) — Author.

2. Filtering and Masking: The technique hides the data with an image
similar, however, only in images with shades of gray;

This technique has a peculiarity in relation to LSB, according to [5] the filtering and masking techniques are more robust for generating stego-images immune to compression and clipping, in addition to inserting the information
in the most significant bits. Because of the insertion in the leftmost bit of the binary chain, colored images are more likely to be detected by the large amount of noise generated, however, it is efficient in images with shades of gray.

  1. Algorithms and Transformations: Techniques that work with
    image characteristics, brightness, saturation and compression.

The use of this technique is possible through the implementation of linear algebra in computation, using discrete Fourier transform, Z transform or
discrete cosine transform (Discrete Cosine Transform — DCT) that quickly became efficient in image processing for its ability to work with storage without lose in compression solving one of the main problems of manipulation and compression of LSB technique [1].

4. Hands-on

4.1. How to play with it? LSB technique

The code is available on github. It is also important to remember, that the following method only works on images lossless (png, bmp…).

4.2. Steps

Let’s do the following order:

1) Get the list of files and compress them.
2) Write the header, that is, use the first 10 pixels to record the size of the zip.
3) Generate a pseudo random order of pixels.
4) Swap the least significant bits of each channel.
5) Write the output image :).

4.3. Reading and stopping criteria

An important constant in the technique is the reading and stopping criteria to be done on the object coverage, some related projects use acronyms or initials to start and end reading. However, the reading criterion used in the work is done after the indication of the artifacts to be hidden in the image. Thus, 10 pixels are used to indicate the size of the files to be hidden (zip), since, reading the bytes in the image will be equal to the size of the compressed file. For this example, we also decided to write 2 bits on the red channel, 1 bit on the blue and 1 bit on the green. So the maximum amount of data we can write to an image is:

T = Heigth * Width / 2 –10

Figure 3 (Header) — Author.

4.4. Details

The first method[4] (putLSB) has the image input, the value
and the pixel into which the value will be inserted. The processing performed by the function is first obtain the value of that pixel in the image, clear the least significant bits used in the channels (2R-1G-1B), and later by bit manipulation insert the value in their respective channels and “return” the modified pixel in its column and line of the image again. The second function (getLSB) does similar processing, however the function has a return referring to the value obtained from the pixel.

Figure 4 (LSB methods) — Author.

Through the technique and method presented, the system is able to mask without modifying the size and without degrading the image. Images with hidden data become visibly imperceptible, even when there is a total change in the image , that is, all pixels undergo modification the method
described will change 1.04% of the total colors of the image. According to [4] the human beings can only identify changes in images when their size of modification is greater than 3%.

References

[1] Gonzalez, R.C., Woods, R.E. and Masters, B.R., 2008. Digital image processing third edition. Pearson International Edition.

[2] Arnold, M.K., Schmucker, M. and Wolthusen, S.D., 2003. Techniques and applications of digital watermarking and content protection. Artech House.

[3] Johnson, N.F., Duric, Z. and Jajodia, S., 2001. Information Hiding: Steganography and Watermarking-Attacks and Countermeasures: Steganography and Watermarking: Attacks and Countermeasures (Vol. 1). Springer Science & Business Media.

[4] Wayner, P., 2009. Disappearing cryptography: information hiding: steganography and watermarking. Morgan Kaufmann.

[5] Popa, R., 1998. An analysis of steganography techniques. Master’s thesis, The Polytechnic University of Timisoara, Timisoara, Romênia.

--

--