Bash, 156
Poiché è vietato l'uso di una vera "libreria di compressione", base64
abuserò invece di coreutils. ( xxd -r
per decodificare l'invio)
0000000: 7461 696c 202d 3120 2430 7c62 6173 6536 tail -1 $0|base6
0000010: 3420 2d77 307c 7472 2058 595a 205c 202c 4 -w0|tr XYZ \ ,
0000020: 2e0a 6578 6974 0a2e 8ade 9978 a9b2 e997 ..exit.....x....
0000030: 7689 68ad 7b22 b576 a67a d617 7289 ec79 v.h.{".v.z..r..y
0000040: cb5e b6e7 ab5d a762 a62b 1c8a 7817 7a58 .^...].b.+..x.zX
0000050: ad61 7b1e 7577 626a 65e7 a27b a69b 25e7 .a{.uwbje..{..%.
0000060: 89b8 577a e8ac 9a87 57b6 29dc 89db a7b5 ..Wz....W.).....
0000070: 7bad 5e56 a8ad e7ad 5dda 25a2 b797 99a8 {.^V....].%.....
0000080: 2769 76a5 8aab 9a99 77ab 6ad5 efa2 5bad 'iv.....w.j...[.
0000090: a5ab 595d 4b57 c22b 225d e9e2 ..Y]KW.+"]..
Ho generato il codice sopra usando questo programma PHP:
<?php
$lorem = '<text here>';
$enclorem = base64_decode( strtr( $lorem, ' ,.', 'XYZ' ) );
$prog = "tail -\$3 \$0|base64 -w0|tr XYZ \\ ,.\nexit\n$1";
for ( $i = 0, $n = strlen( $lorem ); $i < $n; $i++ ) {
$cutlorem = substr( $lorem, 0, $i );
for ( $j = 0, $o = strlen( $enclorem ); $j < $o; $j++ ) {
$cutenclorem = substr( $enclorem, 0, $j );
if ( substr( strtr( base64_encode( $cutenclorem ), 'XYZ', ' ,.' ), 0, $i ) === $cutlorem ) {
break;
}
}
$out = strtr( $prog, array(
'$1' => $cutenclorem,
'$2' => $i,
'$3' => substr_count( $cutenclorem, "\n" ) + 1,
) );
echo "\$i=$i strlen(\$out)=" . strlen( $out ) . "\n";
if ( $i === strlen( $out ) ) {
break;
}
}
echo "\nHexdump:\n";
$p = popen( 'xxd', 'w' );
fwrite( $p, $out );
pclose( $p );
echo "\nFinal output check: ";
$tmp = tmpfile();
fwrite( $tmp, $out );
$md = stream_get_meta_data( $tmp );
ob_start();
passthru( 'bash ' . escapeshellarg( $md['uri'] ) );
$buf = rtrim( ob_get_clean() );
echo $buf === substr( $lorem, 0, strlen( $out ) ) ? 'PASS' : 'FAIL', "\n$buf\n";