I am writing a Image encryption program in which I encode a string inside the image.
I am working with .png images.
Encoding is performed by following steps:
1. Pixels of the image are stored in a 2D array using getRGB().
2. Each Character in the string is converted in to binary form and stored in an array.
3. The LSB of every byte of the 4byte pixel is changed according to every bit of the binary form of the character. LSB of first byte is at 0th position, LSB of second byte is at 8th position, third byte is at 16th position, and fourth byte is at 24th position.
4.After encoding, the modified pixels are written into the original image by using setRGB() method.
For decoding:
1. Read the pixels of the image using getRGB();
2. The reverse method of encoding is applied for retreiving the data.
3. After every 8th bit, int containing the decoded bits is converted in to character. Then initialized with zero for the other character.
if((pixels[i][j] & change)==1)
{
tempText|=1 ;
}
tempText<<=1;
Where change is 1,256,65536,16777216 depending on the iteration. Whose 0th,8th,16th and 24th bits are one.
The code compiles fine. But after decoding, I get weird ascii characters in output. I couldn't find the reason for this. So I am consulting experts here.
code can be found here:
http://ideone.com/hXNbxq
I am working with .png images.
Encoding is performed by following steps:
1. Pixels of the image are stored in a 2D array using getRGB().
2. Each Character in the string is converted in to binary form and stored in an array.
3. The LSB of every byte of the 4byte pixel is changed according to every bit of the binary form of the character. LSB of first byte is at 0th position, LSB of second byte is at 8th position, third byte is at 16th position, and fourth byte is at 24th position.
4.After encoding, the modified pixels are written into the original image by using setRGB() method.
For decoding:
1. Read the pixels of the image using getRGB();
2. The reverse method of encoding is applied for retreiving the data.
3. After every 8th bit, int containing the decoded bits is converted in to character. Then initialized with zero for the other character.
if((pixels[i][j] & change)==1)
{
tempText|=1 ;
}
tempText<<=1;
Where change is 1,256,65536,16777216 depending on the iteration. Whose 0th,8th,16th and 24th bits are one.
The code compiles fine. But after decoding, I get weird ascii characters in output. I couldn't find the reason for this. So I am consulting experts here.
code can be found here:
http://ideone.com/hXNbxq