I'm trying to convert the following code to PHP !!!

can anyone help on this????

<%
function Encrypt (sDatos, sPassword)
Dim Largo, x, y, z, sResult, sAuxResult, sAsc

Largo = Len(sPassword)
sResult = ""
For x = 1 To Len(sDatos)
    y = Asc(Mid(sDatos, x, 1))
    z = Asc(Mid(sPassword, (x Mod Largo) - Largo * ((x Mod Largo) = 0), 1))
    sResult = sResult & Chr(y XOR z)
Next
For i = 1 to Len(sResult)
sAsc = Asc(Mid(sResult,i,1))
          if ( Len(sAsc) < 3 ) then
     sAuxResult = sAuxResult & string(3 - Len(sAsc), "0") & sAsc
else
     sAuxResult = sAuxResult & sAsc
end if
Next
Encrypt = sAuxResult

End Function

function Decrypt (sDatos, sPassword)

Dim Largo, x, y, z, sResult, sAuxResult

For i = 1 to Len(sDatos) Step 3
		sAuxResult = sAuxResult & Chr(Mid(sDatos,i,3))
Next
	sDatos = sAuxResult
Largo = Len(sPassword)
	sResult = ""
For x = 1 To Len(sDatos)
		y = Asc(Mid(sDatos, x, 1))
		z = Asc(Mid(sPassword, (x Mod Largo) - Largo * ((x Mod Largo) = 0), 1))
		sResult = sResult & Chr(y XOR z)
Next
	Decrypt = sResult

End function

%>

FOLLOWING IS WHAT I'VE DONE IN PHP BUT IS NOT WORKING !!!!

<? 

function Encrypt($sDatos,$sPassword) {
$Largo=strlen($sPassword);
$sResult="";

for ($x=1; $x <= strlen($sDatos); $x++) {
	$y = ord(substr($sDatos, $x-1, 1));
	$z = ord(substr($sPassword, ($x % $Largo) - $Largo * ($x % $Largo)-1, 1));
	$sResult .= chr($y ^ $z);
} 

for ($i=1; $i <= strlen($sResult); $i++) {
	$sAsc=ord(substr($sResult, $i-1, 1));
	if (strlen($sAsc) < 3) {
		$sAuxResult .= str_repeat(3 - strlen($sAsc), 0) . $sAsc;
	} else {
		$sAuxResult .= $sAsc;
	} 
} 

$function_ret=$sAuxResult;
return $function_ret;
} 


function Decrypt($sDatos,$sPassword) {
for ($i=1; $i <= strlen($sDatos); $i=$i+3) {
	$sAuxResult .= chr(substr($sDatos, $i-1, 3));
} 

  $sDatos = $sAuxResult;
  $Largo = strlen($sPassword);
  $sResult = "";
  for ($x=1; $x <= strlen($sDatos); $x++) {
	  $y=ord(substr($sDatos, $x-1, 1));
	  $z = ord(substr($sPassword, ($x % $Largo) - $Largo * (($x % $Largo)-1), 1));
	  $sResult .= chr($y ^ $z);
  } 

$function_ret=$sResult;
return $function_ret;
} 


$sPassword = "1JH2345KJH678999";
$crypted  =Encrypt("Text to encript", $sPassword);
$plain =Decrypt($crypted, $sPassword);

print "$crypted <p> $plain";
?>

    thats cos most of those functions arent PHP Functions. Try getting a ASp to PHP Convertor or learning more php and fimilarise yourself with it.

      If I'm not wrong all functions used in the php code I posted 'ARE' php functions!!! I verified them all at http://www.php.net

      I know I need to get more familiar with PHP, I don't need 'YOU' to tell me that, it doesn't help me to answer my question!!!

      If I posted the problem was cos I needed help !!!

      Now, for those willing to help (not critizise), I have published both the php and asp scripts on the net....

      the asp code is working on :

      http://www.mercadodetrabajo.com.uy/visa.asp

      the php code is at:

      http://www.reduruguay.com.uy/visa2.php

      I need the PHP script to return the same as ASP script.

      I'm not either ASP (I hate MS) or PHP experiensed programmer,

      I'm just starting with PHP.

        Write a Reply...