big issue with new encrypted compression tasctic using PNG

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

big issue with new encrypted compression tasctic using PNG

Post by wiseguy12851 »

Below is the code for a new compressed encryption tester which writes the input in PNG format given there are 256 x 3 colors in a true color image allowing for that amount of functions, commands, and ascii characters to be written to the image in one color pixel and read back pixel by pixel.

I have additionally programmed in offset's in the pixel colors allowing for flexibility when it is finished and distributed but somewhere it is either writing wrong or reading wrong or both.

Converts and writes to PNG format code

Code: Select all

<?PHP
 
function getWH($string)
{
    $string = strlen($string); // Count the length
    $string = sqrt($string); // Square root to get box image dimensions
    $string = sprintf("%u.0",$string); // double check it's not negative and remove decimal points
    $string = $string + 1; // if any decimal was removed add an extra row and column to make up for any data loss
    return $string;
}
 
function totalSZ($string)
{
    $string = strlen($string); // Count the length
    $string = $string + $string; // Get the entire image size
    $string = sprintf("%u.0",$string); // double check it's not negative and remove decimal points
    $string = $string + 1; // if any decimal was removed add an extra row and column to make up for any data loss
    return $string;
}
 
$data = $_REQUEST['plaindata']; // Get data
$debug = $_REQUEST['debug']; // Get Debug (if any)
 
$demensions = getWH($data); // get demensions
$totalSize = totalSZ($data); // get total size
$image = imagecreatetruecolor($demensions,$demensions); // Create the image
$BGC = imagecolorallocate($image,"0","0","0"); // prepare black background
imagefill($image,"0","0",$BGC); // Fill image black
 
$stPX = "0"; // Assign X starting position
$enPX = "0"; // Assign Y starting position
$increment = "0"; // Assign the image progress starting position
$dtSt = "0"; // Assign String starting position
 
while($increment <= $totalSize)
{
    $dataTT = substr($data,$dtSt,"1"); // From the current position in the string extract 1 character
        if($debug == 1)
            echo "Converting " . $dataTT;
    $dataTT = bin2hex($dataTT); // Convert it to hexidecimal number
        if($debug == 1)
            echo " to hexi " . $dataTT;
    $dataTT = hexdec($dataTT); // Then to ascii number
        if($debug == 1)
            echo " again to decimal " . $dataTT;
    $dataTT = $dataTT + 48; // Assign a strategic offset for hackers
        if($debug == 1)
            echo " resulting in " . $dataTT . "<br>";
 
    $chCl = rand(1,3); // Pick a color from Red, Green, or Blue for hacker confusion
        switch($chCl)
        {
            case 1:
            $color = imagecolorallocate($image,$dataTT,"0","0"); // Red
            break;
            case 2:
            $color = imagecolorallocate($image,"0",$dataTT,"0"); // Green
            break;
            case 3:
            $color = imagecolorallocate($image,"0","0",$dataTT); // Blue
            break;
        }
        
    imagesetpixel($image,$stPX,$enPX,$color); // Write the color
        if($debug == 1)        
             echo "Wrote X: " . $stPX . " Y: " . $enPX . " Color Code: " . $chCl . " Color Value: " . $dataTT. "<br>";
 
    $increment = $increment + 1;
    if($stPX == $demensions) // if at end of picture then loop do a carriage like return
    {
        $stPX = "0";
        $enPX = $enPX + 1;
    }
    else // or proceed as normal
    {
    $stPX++;
    }
 
    $dtSt = $dtSt + 1; // proceed in the string
}
if($debug == 3) // tell browser to show the image and not download
{
    header("Content-Type: image/png");
}
else if($debug == 4) // tell browser to download the PNG filename
{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=dataimage.png");
header("Content-Type: image/png");
header("Content-Transfer-Encoding: binary");
}
else // tell browser to download the ideal filename
{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=dataimage.efidi");
header("Content-Type: image/png");
header("Content-Transfer-Encoding: binary");
}
imagepng($image); // write the image
 
?>
The code for the decrypter.

Code: Select all

<?PHP
move_uploaded_file($_FILES["imagedata"]["tmp_name"],"upload/" . $_FILES["imagedata"]["name"]); // copy file to temp directory
$image = "upload/" . $_FILES["imagedata"]["name"]; // copy it to folder
$dataimg = imagecreatefrompng($image); // open file
 
$imagew = imagesx($dataimg); // get width
$imageh = imagesy($dataimg); // get height
echo "Reported Image width: " . $imagew . " and height: " . $imageh . "<br>";
$totalSize = $imagew + $imageh; // get total width and height
 
$stPX = "0"; // set starter pixel X
$enPX = "0"; // set starter pixel Y
$increment = "0"; // set progress location
 
while($increment <= $totalSize)
{
        $tcolor = imagecolorat($dataimg,$stPX,$enPX); // get the pixel exact color
        echo "Converting " . $tcolor;
        $tcolor = imagecolorsforindex($dataimg,$tcolor); // translate the value
        echo " to index <ul><li>Red: " . $tcolor[red] . "</li><li>Blue: " . $tcolor[blue] . "</li><li>Green: " . $tcolor[green] . "</li><li>Alpha: " . $tcolor[alpha] . "</li></ul>";
        $tcolor = $tcolor[red] + $tcolor[blue] + $tcolor[green] + $tcolor[alpha]; // combine the colors (allows flexibility in future for other types)
        echo " acsii value: " . $tcolor;
    $tcolor = $tcolor - 48; // Remove offset
        if($tcolor == "-48") // if none then bring to 0
                $tcolor = "0";
        echo " acsii value decoded " . $tcolor;
        $tcolorFinal = $tcolorFinal . chr($tcolor); // add the decoded message to into the output string
        echo " acsii value symbol " . chr($tcolor) . "<br>";
 
    $increment = $increment + 1;
    if($stPX == $imagew) // if at end do carriage like return
    {
        $stPX = "0";
        $enPX++;
                echo "Cursor Retuurn: X: " . $stPX . " Y: " . $enPX . "<br>";
    }
    else // proceed normally
    {
    $stPX++;
        echo "Cursor Proceed: X: " . $stPX . " Y: " . $enPX . "<br>";
    }
}
 
echo $tcolorFinal; // print final output
 
?>
Of course when it's finished it will be properly formatted

to access a live demo click the link below, you'll also see what I mean by the read and/or write problems
http://expressfixit.net/demo-EC/
Post Reply