Page 1 of 1

[SOLVED] Unsolvable parse error!

Posted: Thu Jan 29, 2004 6:40 pm
by EndTwist
Hello,

I seem to get an error on line 5 of this function, no matter what I do. I repeatedly get a "parse error" on that specific line. What am I missing?

Code: Select all

function encryptPW($strPass) {
 $arrTable = array(0 => 84, 105, 99, 47, 84, 111, 99);
 $strEncrypted = "0x";
 for($lngX=0; $lngX < strlen($strPass); $lngX++) {
   $strHex = dechex(ord(strstr($strPass, $lngX+1, 1)) ~ $arrTable($lngX % 7)));
   if(("&H" + $strHex) < 16) { $strEncrypted .= "0";
 }
 return strtolower($strEncrypted);
}

Posted: Thu Jan 29, 2004 7:29 pm
by Meteo
missing a brace

Code: Select all

function encryptPW($strPass)
{ 
$arrTable = array(0 => 84, 105, 99, 47, 84, 111, 99); 
$strEncrypted = "0x"; 
for($lngX=0; $lngX < strlen($strPass); $lngX++)
{ 
   $strHex = dechex(ord(strstr($strPass, $lngX+1, 1)) ~ $arrTable($lngX % 7))); 
   if(("&H" + $strHex) < 16)
          { $strEncrypted .= "0"; } /* <=== right there, don't need the braces there really */
} 
return strtolower($strEncrypted); 
}

Posted: Thu Jan 29, 2004 7:52 pm
by EndTwist
Fixed it, but it still doesn't work

Code: Select all

function encryptPW($strPass) {
 $arrTable = array(84, 105, 99, 47, 84, 111, 99);
 $strEncrypted = "0x";
 for($lngX=0; $lngX < strlen($strPass); $lngX++) {
   $strHex = dechex(ord(strstr($strPass, $lngX+1, 1)) ~ $arrTable[$lngX % 7]);
   if(("&H" + $strHex) < 16) { $strEncrypted .= "0"; }
 }
 return strtolower($strEncrypted);
}

Posted: Thu Jan 29, 2004 9:06 pm
by Meteo
I tried to go through your code, this line...

if (("&H" + $strHex) < 16)

from what I can tell, $strHex is a string, and "&H" is definitely one. adding the two together and then comparing it like a numerical value isn't the best idea, I think you might want this...

if (strlen("&H" . $strHex) < 16)

if this doesn't work, I'll try some actual testing, debugging isn't the best unless it's tested :D

Posted: Fri Jan 30, 2004 3:20 am
by twigletmac
What does the parse error say exactly?

Mac

Posted: Fri Jan 30, 2004 3:34 am
by markl999
You can't do, for example, $a ~ $b that results in a parse error.
It's either ~ $a ... or ~ $b , as ~ is the bitwise not operator and only acts only a single var. Maybe you want one of the other bitwise operators that work with 2 values, e.g & | ^

Also, strstr($strPass, $lngX+1, 1) .. strstr only takes 2 arguments "string strstr ( string haystack, string needle)" , so not sure what the extra ,1 is for :o

Posted: Fri Jan 30, 2004 6:23 am
by EndTwist
Thanks.

I fixed the ~, which I changed to Xor (what it needed to be).

I also fixed strstr, it should have been substr.