Coding Challenge #2! (115)

23 Name: Albright!LC/IWhc3yc 05/01/18(Tue)09:54 ID:z4JMghGA

A PHP-powered text obfuscator, for OCR resistance. Originally written for a project I never released, I've recently tweaked it for a project I'm working on now which I'll also probably never release. Probably needs some tweaking; it obfuscates a little too well at times...

It weighs in at under 1.5K. It could be made smaller by using one-character variable names and reducing whitespace and such, but I'm actually using this code in a project, so it has to be legible...

Incidentally, anyone know the UNIX command to get the actual size of a file (not the whatchamacallit du -h provides)? (lol "duh" lol)

<?php
$code="Text to obfuscate";
$clen=strlen($code);
if (mt_rand(0,1)==0) {
$back=mt_rand(0,50);
$dark=true;
}
else {
$back=mt_rand(205,255);
$dark=false;
}
$right=mt_rand(-1,4);
for ($i=0; $i<$clen; $i++) {
$pos[$i]=mt_rand($right, $right+4);
$fonts[$i]=mt_rand(4,5);
$right=$pos[$i]+imagefontwidth($fonts[$i])+2;
}
$theimg=imagecreate($right, 16);
imagecolorallocate($theimg,$back,$back,$back);
$lines=$clen*5;
for ($i=0; $i<$lines; $i++) {
if ($dark==true) {
$clr=mt_rand(0,127);
}
else {
$clr=mt_rand(128,255);
}
$clr=imagecolorallocate($theimg,$clr,$clr,$clr);
imageline($theimg,mt_rand(0,$right),0,mt_rand(0,$right),16,$clr);
}
for ($i=0; $i<$clen; $i++) {
if ($dark==true) {
$clr=mt_rand(191,255);
}
else {
$clr=mt_rand(0,63);
}
$clr=imagecolorallocate($theimg,$clr,$clr,$clr);
$horiz=mt_rand(-1,16-imagefontheight($fonts[$i]));
imagestring($theimg, $fonts[$i], $pos[$i], $horiz, $code{$i}, $clr);
for ($j=0; $j<($fonts[$i]*2); $j++) {
imagesetpixel($theimg, mt_rand($pos[$i],$pos[$i]+imagefontwidth($fonts[$i])),mt_rand($horiz, $horiz+imagefontheight($fonts[$i])), $clr);
}
}

header("Content-type: image/png");
imagepng($theimg);
?>
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: