title: LSB Encryption and Decryption
body: <p>I'm using LSB encryption method to hide data in an image. When I try to get the decrypted message, the output message doesn't look like the original message. What am I doing wrong and how to fix it?</p>
  
  <pre><code>function imagehide()
  % hide message in image
  m = 'computer';
  im = imread('lena_1.png');
  im = rgb2gray(im);
  imtool(im);
  a = dec2bin(m,8);
  a = a(:);
  m = dec2bin(im);
  for i=1:size(a)
      m(1,8)=a(i);
  end;
  k = bin2dec(m);
  k = reshape(k,256,256);
  k = uint8(k);
  imwrite(k,'ste.png');
  imtool(k);
  % get message from image%
  a = imread('ste.png');
  sm = 8;
  s = dec2bin(a);
  for i = 1:sm*8;
      l(i) = s(i,8);
  end
  n = reshape(l,sm,8);
  n = bin2dec(n);
  n = char(n);
  n = n';
  disp(n);
  end
  </code></pre>