[SOLVED] Unsolvable parse error!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

[SOLVED] Unsolvable parse error!

Post 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);
}
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post 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); 
}
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

Post 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);
}
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does the parse error say exactly?

Mac
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
EndTwist
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2004 6:40 pm

Post 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.
Post Reply