> 16) & 0xFF; $green = ($rgb >> 8) & 0xFF; $blue = $rgb & 0xFF; if(is_even($red)) { $binstream .= "1"; } else { $binstream .= "0"; } if(is_even($green)) { $binstream .= "1"; } else { $binstream .= "0"; } if(is_even($blue)) { $binstream .= "1"; } else { $binstream .= "0"; } return $binstream; } function steg_hide($maskfile, $hidefile) { // hides $hidefile in $maskfile // initialise some vars $binstream = ""; $recordstream = ""; $make_odd = Array(); // ensure a readable mask file has been sent $extension = strtolower(substr($maskfile['name'],-3)); if($extension=="jpg") { $createFunc = "ImageCreateFromJPEG"; /* } else if($extension=="png") { $createFunc = "ImageCreateFromPNG"; } else if($extension=="gif") { $createFunc = "ImageCreateFromGIF"; */ } else { return "Only .jpg mask files are supported"; } // create images $pic = @ImageCreateFromJPEG($maskfile['tmp_name']); $attributes = @getImageSize($maskfile['tmp_name']); $outpic = @ImageCreateFromJPEG($maskfile['tmp_name']); if(!$pic || !$outpic || !$attributes) { // image creation failed return "cannot create images - maybe GDlib not installed?"; } // read file to be hidden $data = file_get_contents($hidefile['tmp_name']); // generate unique boundary that does not occur in $data // 1 in 16581375 chance of a file containing all possible 3 ASCII char sequences // 1 in every ~1.65 billion files will not be steganographisable by this script // though my maths might be wrong. // if you really want to get silly, add another 3 random chars. (1 in 274941996890625) // ^^^^^^^^^^^^ would require appropriate modification to decoder. do { $boundary = chr(rand(0,255)).chr(rand(0,255)).chr(rand(0,255)); } while(strpos($data,$boundary)!==false && strpos($hidefile['name'],$boundary)!==false); // add boundary to data $data = $boundary.$hidefile['name'].$boundary.$data.$boundary; // you could add all sorts of other info here (eg IP of encoder, date/time encoded, etc, etc) // decoder reads first boundary, then carries on reading until boundary encountered again // saves that as filename, and carries on again until final boundary reached // check that $data will fit in maskfile if(strlen($data)*8 > ($attributes[0]*$attributes[1])*3) { // remove images ImageDestroy($outpic); ImageDestroy($pic); return "Cannot fit ".$hidefile['name']." in ".$maskfile['name'].".
".$hidefile['name']." requires mask to contain at least ".(intval((strlen($data)*8)/3)+1)." pixels.
Maximum filesize that ".$maskfile['name']." can hide is ".intval((($attributes[0]*$attributes[1])*3)/8)." bytes"; } // convert $data into array of true/false // pixels in mask are made odd if true, even if false for($i=0; $i> 16) & 0xFF; $cols[] = ($rgb >> 8) & 0xFF; $cols[] = $rgb & 0xFF; for($j=0 ; $j