Steganography (Encode image)

Never worry about theory as long as the machinery does what it's supposed to do.
';' $message .= 'Robert A. Heinlein.
'; $message .= 'Using PHP, is it possible to apply Steganography (Store a hidden message) to an image? If so, how?
'; $message .= 'Close the nessage with ". chr(0)"

' . chr(0); */ $myfile = fopen( "../textfile.txt", "r" ) or die( "Unable to open file!" ); //echo fread($myfile,filesize("textfile.txt")); $message = fread( $myfile,filesize( "../textfile.txt" ) ); echo '

Text = ' . htmlspecialchars( $message ) . '

' . PHP_EOL; $message .= chr(0); // text should end with this character fclose( $myfile ); $x = imagesx( $img ); $y = imagesy( $img ); $px = 0; $py = 23; $h = 23; for( $i = 0; $i $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 ); } imagepng( $img, $imgFileOutput ); //echo imagejpeg( $img, $imgFileOutput ); //met jpg lukt het niet imagedestroy( $img ); ?>

Result

Original image.

Image with hidden text.

Decoded message :

With code :


To index
To Decode