@ 2014-08-19T09:18:48Z <?php
class LZW {
function compress($uncompressed) {
$dictSize = 256;
$dictionary = array();
for ($i = 0; $i < 256; $i++) {
$dictionary[chr($i)] = $i;
}
$w = "";
$result = "";
for ($i = 0; $i < strlen($uncompressed); $i++) {
$c = $this->charAt($uncompressed, $i);
$wc = $w.$c;
if (isset($dictionary[$wc])) {
$w = $wc;
} else {
if ($result != "") {
$result .= ",".$dictionary[$w];
} else {
$result .= $dictionary[$w];
}
$dictionary[$wc] = $dictSize++;
$w = "".$c;
}
}
if ($w != "") {
if ($result != "") {
$result .= ",".$dictionary[$w];
} else {
$result .= $dictionary[$w];
}
}
return $result;
}
function decompress($compressed) {
$compressed = explode(",", $compressed);
$dictSize = 256;
$dictionary = array();
for ($i = 1; $i < 256; $i++) {
$dictionary[$i] = chr($i);
}
$w = chr($compressed[0]);
$result = $w;
for ($i = 1; $i < count($compressed); $i++) {
$entry = "";
$k = $compressed[$i];
if (isset($dictionary[$k])) {
$entry = $dictionary[$k];
} else if ($k == $dictSize) {
$entry = $w.$this->charAt($w, 0);
} else {
return null;
}
$result .= $entry;
$dictionary[$dictSize++] = $w.$this->charAt($entry, 0);
$w = $entry;
}
return $result;
}
function charAt($string, $index){
if($index < mb_strlen($string)){
return mb_substr($string, $index, 1);
} else{
return -1;
}
}
}
$lzw = new LZW();
echo $lzw->decompress("dGl0bGUgw4ljaGFuZ2VzIExNNwoKZVNtaWxlLT4rTE03OiBBcnRpY2xlCkxNNy0-LQAWBjogUmV0b3VyABQJACUPUkVDACEPTURTAEkQT1AAPhZPUAoAaAUtPgBlCEltYWdlIHN0b2Nr");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 Fatal error: Uncaught TypeError: chr(): Argument #1 ($codepoint) must be of type int, string given in /in/0iiFb:42
Stack trace:
#0 /in/0iiFb(42): chr('dGl0bGUgw4ljaGF...')
#1 /in/0iiFb(70): LZW->decompress(Array)
#2 {main}
thrown in /in/0iiFb on line 42
Process exited with code 255 . Output for 7.4.0 - 7.4.33 Warning: chr() expects parameter 1 to be int, string given in /in/0iiFb on line 42
Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.25 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33