Hi,
Using PHP, is it possible to apply Steganography (Store a hidden message) to an image? If so, how?
Hi,
Using PHP, is it possible to apply Steganography (Store a hidden message) to an image? If so, how?
How is it normally done? I'm not versed in Steganography, if you can explain how one would do it normally, we could possibly tell you if it's possible in PHP.
Rather than me put this in my own words, go to the following URL - This pretty much explains the technique used.
You need to look at the www.php.net/image functions.
It should be easy to hide a message in an image quite easily.
Hi Once Again,
Just a quick note, as I feel people are getting the wrong idea to what I mentioned above.
Basically, a user will be greeted with a file field and a message field (textbox). Upon the user clicking "Browse", selecting there image, entering a message and the submit button being pressed, the message entered should be add secretly to the image/file. (Not visible within the picture)
Upon another/same user clicking "Browse" within another form containing a file field a textbox and a "decode" button, the message embedded previously in the image, should be revealed within the textbox.
This way, people can send message to one another, without other people having knowledge that the embedded message/text exists.
Do you know how to do this in some image editing program (Fireworks, Photoshop, Gimp, Inkscape, etc.)? If so, then explain how you'd do it. I understand the concept, I just don't see how it would be "hidden" in a regular image.
I believe the idea is that some pre-determined pattern of individual pixels throughout the image would have their values set/adjusted based on the bits and bytes of information to be transmitted. One way might be to convert your message into a binary string representation (every 8 bits relating to one ASCII character code. Then set one bit of each pixel's color encoding to match that sequence of ones and zeros, only changing the least significant bits for each color.
With the image functions, you'd loop through each pixel with imagecolorat() and imagesetpixel for the encoding/decoding operations.
I tried adjusting the image pixels, but the jpeg compression destroyed the info.
I basically only changed the RGB value by 3 bits per colour, it was not very obvious, but I couldn't read the info after saving it.
Hmm...yeah, any lossy compression routine would be a problem with that method. You would either have to directly mess with the binary data of the compressed JPEG file, or use something like a BMP image with no compression, or I believe PNGs use a lossless compression algorithm, don't they?
Yes, png works ok.
Here is the test code I wrote.
Don't laugh too hard.
http://halfabee.powweb.com/test/steg.php
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
$img = imagecreatefromjpeg("deadsea.jpg");
$message = 'Hello world'.chr(0);
$x=imagesx($img);
$y=imagesy($img);
$px=0;
$py=23;
$h = 23;
for( $i=0;$i<strlen($message);$i++ ) {
$px += $h;
if( $px > $x ) {
$px = $px%$x;
$py += $h;
}
$rgb = imagecolorat($img, $px, $py);
$R = ($rgb >> 16) & 0xFF;
$G = ($rgb >> 8) & 0xFF;
$B = $rgb & 0xFF;
$m = ord($message{$i});
$R = ($R&0xf8)| ($m&0x07);
$G = ($B&0xf8)|(($m>>3)&0x07);
$B = ($B&0xf8)| (($m>>6)&0x03);
// $R = ($m&0x07);
// $G = (($m>>3)&0x07);
// $B = (($m>>6)&0x03);
$t = imagecolorallocate($img, $R , $G , $B );
imagesetpixel( $img , $px,$py , $t );
}
echo imagepng($img,'deadsea2.png');
imagedestroy($img);
echo $img = imagecreatefrompng("deadsea2.png");
$message='';
$x=imagesx($img);
$y=imagesy($img);
$px=0;
$py=23;
$h = 23;
while( TRUE ){
$px += $h;
if( $px > $x ) {
$px = $px%$x;
$py += $h;
}
$rgb = imagecolorat($img, $px, $py);
$R = ($rgb >> 16) & 0x7;
$G = ($rgb >> 8) & 0x7;
$B = $rgb & 0x3;
$m = $R + ($G<<3) + ($B<<6);
$g=dechex($G<<3);
$b=dechex($B<<6);
if( $m==0 ) break;
$message .= chr($m);
}
?>
<img src='deadsea.jpg' ><img src='deadsea2.gif' ><br>
Decoded message <? echo $message ?>
<pre>
<? echo `ls -la dead*`; ?>
</body>
</html>
HalfaBee, would it be possible for you to comment your code, so I can get to grips with what it is doing and how?