title: Understanding image steganography by LSB substitution method
body: <p>I am having a very hard time in understanding the <a href="https://pdfs.semanticscholar.org/df89/bacee8720f3b3be19d96e6eac6429a2a8130.pdf" rel="nofollow noreferrer">LSB based steganography</a> method given in Section 2. The examples in the internet are very confusing and unclear. I am following the Matlab implementation <a href="https://www.mathworks.com/matlabcentral/fileexchange/41326-steganography-using-lsb-substitution" rel="nofollow noreferrer">https://www.mathworks.com/matlabcentral/fileexchange/41326-steganography-using-lsb-substitution</a> and the paper titled, "A SURVEY ON IMAGE STEGANOGRAPHY USING LSB SUBSTITUTION 
  TECHNIQUE " download link (<a href="https://irjet.net/archives/V4/i5/IRJET-V4I566.pdf" rel="nofollow noreferrer">https://irjet.net/archives/V4/i5/IRJET-V4I566.pdf</a>)</p>
  
  <p>Section 5 of this paper gives an example of the LSB based method. Suppose, <code>P1 = [10011011], P2 = [01101010], P3 = [11001100]</code> are the 3 bytes of the cover image into which the message <code>M =  [011]</code> is to be embedded. The result of the embedding is <code>P1 =  [10011010], P2 = [01101011], 
  P3 =  [11001101]</code>. </p>
  
  <p>I am clueless how this answer comes. Can somebody please help in giving the steps/working example to clear the concept?</p>
  
  <p>Based on my understanding of the Matlab code, 
  <code>Stego = uint8(round(bitor(bitand(x, bitcmp(2^n - 1, 8)) , bitshift(y, n - 8))));</code></p>
  
  <p>if <code>n</code> is the number of bits to be substituted, then the group of <code>n</code> bits are replaced by doing a complement/ comparison of the group of <code>n</code> bits of the cover image (<code>x</code> variable) with the <code>n</code> bits of the message (<code>y</code> 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.</p>