I need, at work to convert the following functions to php...
I tried, but I don't get the same result...
Please Gurus!!!
Thanks.

<script type="text/javascript">
<!--
/* --- private --- */
function Login()
{
var Ret = true;

if((document.all("txtUser").value).length > 0)
{
if(document.all("txtPassword").value != "")
{
Ret = CheckComValue(document.all("txtPassword").value);
}

if(CheckComValue(document.all("txtUser").value) && (Ret != false))
{
var strKey = "%#000500";
var strUser = Encryption(document.all("txtUser").value, strKey, 32);
var strPass = Encryption(document.all("txtPassword").value, strKey, 32);
var strURL = "./ulogin.cgi?USER=" + strUser + "&PASS=" + strPass + "&KEY=" + strKey + RetTempParam();
window.open(strURL, "_self", "menubar=no,status=yes,width=1024,height=768,left=0,top=0");

}
else
{
alert("[User Name/Password] Input character is incorrect.");
}
}
}

function RetTempParam()
{
var cdtNow = new Date();
var strRet = "&TEMP=" + cdtNow.getTime();

return strRet;
}

function CheckComValue(strParam)
{
var strBaseChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

var bRet = true;
var iParamLen = strParam.length;

for (var iIndex = 0; iIndex < iParamLen; iIndex++)
{
if (strBaseChar.indexOf(strParam.charAt(iIndex)) == -1)
{
bRet = false;
break;
}
}

return bRet;
}

function Encryption(strInput, strKey, iSize)
{
var strCode = new Array;

for (i=0 ;i < iSize ;i++)
{

if (i < strInput.length)
{
asciiCode = strInput.charCodeAt(i);

}
else
{
asciiCode = 0;

}

if (i != 0 )
{
asciiCode ^= maskCode;

}

for (j=0 ;j < (strKey.length) ;j++)
{
asciiKey =strKey.charCodeAt(j);

asciiCode = (asciiCode ^ asciiKey) - asciiKey;

}
maskCode = asciiCode & 0xFF;

hexCode = maskCode.toString(16);

if (maskCode < 16)
{
strCode += "0";
}
strCode += String(hexCode);
}
return strCode;
}

//-->
</script>

here is my try....
PHP below..............


<?php
function CheckComValue($strParam)
{
$strBaseChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$bRet = true;
$iParamLen = strlen($strParam);
for ($iIndex = 0; $iIndex < $iParamLen; $iIndex++)
{
$pos=strrpos($strBaseChar, substr($strParam, $iIndex, 1));
if($pos === false)
$bRet = false;
}
return $bRet;
}
function hexstr($hex)
{
$string="";
for ($i=0;$i<strlen($hex)-1;$i+=2)
$string.=chr(hexdec($hex[$i].$hex[$i+1]));
return $string;
}

function Encryption($strInput, $strKey, $iSize)
{ $nbArray=0;
$strCode= array();
echo $strInput;
for ($i=0 ;$i < $iSize ;$i++)
{
if($i < strlen($strInput))
{
$asciiCode = ord(substr($strInput,$i,1));
}
else
{
$asciiCode = 0;
}

if ($i != 0 )
{
$asciiCode = $asciiCode ^ $maskCode;
echo $asciiCode."\n";
}

for ($j=0 ;$j < strlen($strKey) ;$j++)
{
$asciiKey =substr($strKey, $j, 1);
$asciiCode = ($asciiCode ^ $asciiKey) - $asciiKey;
}
$maskCode = $asciiCode & 0xFF;
$hexCode = hexstr($maskCode);

if ($maskCode < 16)
{
$strCode[$nbArray++] = "0";
}
$strCode[$nbArray++] = $hexCode;
}
$strCodestr="";
for ($i =0; $i < sizeof($strCode); $i++) {
$strCodestr = $strCodestr.$strCode[$i];
}
return $strCodestr;
}
echo Encryption("ADMIN", "105634", 32);
?>