Understanding image steganography by LSB substitution method

寵の児 提交于 2019-12-24 18:26:19

问题


I am having a very hard time in understanding the LSB based steganography method given in Section 2. The examples in the internet are very confusing and unclear. I am following the Matlab implementation https://www.mathworks.com/matlabcentral/fileexchange/41326-steganography-using-lsb-substitution and the paper titled, "A SURVEY ON IMAGE STEGANOGRAPHY USING LSB SUBSTITUTION TECHNIQUE " download link (https://irjet.net/archives/V4/i5/IRJET-V4I566.pdf)

Section 5 of this paper gives an example of the LSB based method. Suppose, P1 = [10011011], P2 = [01101010], P3 = [11001100] are the 3 bytes of the cover image into which the message M = [011] is to be embedded. The result of the embedding is P1 = [10011010], P2 = [01101011], P3 = [11001101].

I am clueless how this answer comes. Can somebody please help in giving the steps/working example to clear the concept?

Based on my understanding of the Matlab code, Stego = uint8(round(bitor(bitand(x, bitcmp(2^n - 1, 8)) , bitshift(y, n - 8))));

if n is the number of bits to be substituted, then the group of n bits are replaced by doing a complement/ comparison of the group of n bits of the cover image (x variable) with the n bits of the message (y variable). If the bits are same, then no replacement, else the bits are swapped. I dont't know if my understanding is correct or not.


回答1:


Your confusion stems from the fact that all 3 sources you're looking at talk about something different.

Paper 2, section 5

This describes the most basic form of LSB pixel substitution steganography. Each pixel is described by 8 bits. For each pixel we clear out the LSB and substitute it with one bit of the secret message. For example,

pixels = [xxxxxxxa, xxxxxxxb]
message = [c, d]
stego_pixels = [xxxxxxxc, xxxxxxxd]

Where x, a, b, c and d are bits and we don't care what x is.

Paper 1, section 2

This is the generalised form of LSB pixel substitution steganography. Instead of embedding the secret in the LSB, you embed it in the k-most LSBs. If k = 1, then we have the simple form described above. The mathematical equations is this section mean the following:

  1. We have an image of size MxN, with each pixel having a value between 0 and 255 (8 bits).
  2. We have an n-bit message, with each bit being either 0 or 1. For example, for 12 bits it'd be m = [a, b, c, d, e, f, g, h, i, j, k, l].
  3. Since we'll be embedding k bits per pixel, we group our message bits in groups of k. Assume that k = 3, then, m' = [abc, def, ghi, jkl]. Obviously, each group can have a value between 0 and 2^k - 1. Furthermore, the number of groups in m' cannot exceed the size of our image, or we won't be able to embed the whole message.
  4. We clear out the last k bits from each pixel and we substitute them with one group of m'. When you take the modulo of a number with 2^k, the remainder you get is the last k bits of the original number. So by subtracting them, we clear out the last k bits.
  5. Similar to the previous step, if we want to extract the message, we take the modulo of each pixel with 2^k to get the last k bits, where we have embedded our message. It's trivial to stitch these bit groups and obtain the original message, m, back.

Matlab code

This code hides an image of size MxN to a cover image of the same size. The idea here is the MSB holds the most information about the image and the LSB the least. For example, this is the bit plane decomposition of this image.

If we decide to hide k bits from the secret image, we want those to be the k most significant bits. Similarly, we can hide them in the k least significant bits of the cover image. The larger the k value, the more bits you'll hide from the secret for a more faithful reconstruction, but the more distortion you'll introduce to the cover.

Let's break down the nested functions in the code to see what they do. I'll use k instead of n to maintain consistency with the above sections.

bitcmp(2^k - 1, 8) creates the complement of 2^k - 1 for 8 bits. For example, if k = 3, then 2^k - 1 is like having the bits 00000111 and obviously its complement is 11111000. We're going to use this number as a mask, so mask = bitcmp(2^k - 1, 8).

bitand(x, mask) zeroes out the last k bits of the cover image, x. This is the bitwise AND operation and the reason we called the second part a mask is because anywhere we have a 1, we keep the original bit and anywhere we have a 0, we get a 0. Let's call cleared_pixels = bitand(x, mask).

bitshift(y, 8 - k) keeps only the k most significant bits of the secret. For example, for k = 3 we achieve abcxxxxx -> 00000abc. This is done by shifting the number 5 places to the right. This is a logical shift operation. We'll call this result secret = bitshift(y, 8 - k).

Finally, bitor(cleared_pixels, secret) simply combines the two together. The cleared pixels have the last k bits cleared and the secret is at most k bits, so the two parts don't interact; we get a pure combination.



来源:https://stackoverflow.com/questions/49638628/understanding-image-steganography-by-lsb-substitution-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!