All pastes #741570 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-18 20:27 UTC
rendered paste body
<?php

$positions = array();
$contents = file_get_contents("corrupted.png.bz2");
for ($z = 0; $z < strlen($contents); $z++ )
{
if ( $contents[$z] == "\r" && $contents[$z+1] == "\n")
array_push($positions, $z);
}


$replace = str_replace("\r\n","+\n",$contents);


echo 'Checking 1 at a time<br>';


foreach ($positions as $i)
{
$buffer = $replace;
$buffer[$i] = "\r";
$new = str_replace("+\n","\n",$buffer);//keep right size
$data = bzdecompress($new);
if ( $data != -4  && $data != "")
{
file_put_contents("solution.png", $data);
exit('Fixed');
}
}
 
echo 'Checking 2 at a time<br>';

foreach ($positions as $i)
foreach ($positions as $j)
{
if ( $i >= $j ) continue;//don't check same combo twice
echo $i . ' '. $j . '<BR>';
$buffer = $replace;
$buffer[$i] = "\r";
$buffer[$j] = "\r";
$new = str_replace("+\n","\n",$buffer);
$data = bzdecompress($new);
if ( $data != -4  && $data != "")
{
file_put_contents("solution.png", $data);
exit('Fixed');
}
}
        

echo 'Checking 3 at a time<br>';

foreach ($positions as $i)
foreach ($positions as $j)
foreach ($positions as $k)
{
if ( $i >= $j || $j >= $k ) continue;
$buffer = $replace;
$buffer[$i] = "\r";
$buffer[$j] = "\r";
$buffer[$k] = "\r";
$new = str_replace("+\n","\n",$buffer);
$data = bzdecompress($new);
if ( $data != -4  && $data != "")
{
file_put_contents("solution.png", $data);
exit('Fixed');
}
}