<?php
//modified by Robert Camner, Nov. 2006

$code = $_GET['cpt'];

$captchaText=encryptDecrypt($code);
$newImage = imagecreate(11*strlen($captchaText),25); //create background image template
$background = imagecolorallocate($newImage,138,92,69); //create brown background color

$lineColor = imagecolorallocate($newImage,233,239,239);//line color 
$textColor = imagecolorallocate($newImage, 255, 255, 255);//text color-white

imageline($newImage,1,1,40,40,$lineColor);//create line 1 on image 
imageline($newImage,1,100,60,0,$lineColor);//create line 2 on image 
imageline($newImage,1,50,40,0,$lineColor);//create line 3 on image 

imageStringCentered($newImage, 5, encryptDecrypt($code), $textColor);
//imagestring($newImage, 5, 10, 5, encryptDecrypt($code), $textColor);// Draw a random string horizontally 

header("Content-type: image/jpeg");// output the image 

imagejpeg($newImage);//Output image to browser 

function encryptDecrypt($strMessage) 
{ 
	//Function : encrypt/decrypt a string message v.1.0  without a known key 
	//Author   : Aitor Solozabal Merino (spain) 
	//Email    : aitor-3@euskalnet.net 
	//Date     : 01-04-2005 
   	$lenStrMessage=strlen($strMessage); 
   	$strEncryptedMessage=""; 
   	FOR ($position = 0;$position<$lenStrMessage;$position++)
	{ 
       	$strEncryptedMessage .= chr((ord(substr($strMessage, $position, 1))) ^ ((255+(($lenStrMessage +$position)+1)) % 255)); 
    } 
    return $strEncryptedMessage; 
}

function imageStringCentered ($img,$font,$text,$color) 
{
 	while (strlen($text) * imagefontwidth($font) > imagesx($img)) 
	{
  		if ($font > 1) { $font--; }
  		else { break; }
 	}
 	$cy = (imagesy($img)/2) - (imagefontheight($font)/2);
 	imagestring($img,$font,imagesx($img) / 2 - strlen($text) * imagefontwidth($font) / 2,$cy,$text,$color);
}


?>
