Register Guidelines E-Books Search Today's Posts Mark Forums Read

 09-15-2004, 07:34 AM #181 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 PHP Code: ``` \$ch = mix(\$a,\$b,\$c); \$ch=(((\$ch/7) << 2) | ((\$ch%13)&7)); \$prbuf = array(); \$prbuf[0]=\$ch; for(\$i=1; \$i<20; \$i++) {       \$prbuf[\$i]=\$prbuf[\$i-1]-9; } \$ch=mix(\$prbuf, 80, 0xe6359a60); printf('CH: 6%u', \$ch);  ```
 09-15-2004, 09:58 AM #182 Jelko Nameless Being Hm I tried to implement Tarakan's and Alex's code, but somehow the resulting checksum is not right: Code: ```>1); \$a &= (~\$z); \$a |= 0x40000000; \$a = (\$a>>(\$b-1)); } else { \$a = (\$a>>\$b); } return \$a; } function mix(\$a,\$b,\$c) { \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,13)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<8); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,13)); \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,12)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<16); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,5)); \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,3)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<10); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,15)); return array(\$a,\$b,\$c); } function GoogleCH(\$url, \$length=null, \$init=GOOGLE_MAGIC) { if(is_null(\$length)) { \$length = sizeof(\$url); } \$a = \$b = 0x9E3779B9; \$c = \$init; \$k = 0; \$len = \$length; while(\$len >= 12) { \$a += (\$url[\$k+0] +(\$url[\$k+1]<<8) +(\$url[\$k+2]<<16) +(\$url[\$k+3]<<24)); \$b += (\$url[\$k+4] +(\$url[\$k+5]<<8) +(\$url[\$k+6]<<16) +(\$url[\$k+7]<<24)); \$c += (\$url[\$k+8] +(\$url[\$k+9]<<8) +(\$url[\$k+10]<<16)+(\$url[\$k+11]<<24)); \$mix = mix(\$a,\$b,\$c); \$a = \$mix[0]; \$b = \$mix[1]; \$c = \$mix[2]; \$k += 12; \$len -= 12; } \$c += \$length; switch(\$len) /* all the case statements fall through */ { case 11: \$c+=(\$url[\$k+10]<<24); case 10: \$c+=(\$url[\$k+9]<<16); case 9 : \$c+=(\$url[\$k+8]<<8); /* the first byte of c is reserved for the length */ case 8 : \$b+=(\$url[\$k+7]<<24); case 7 : \$b+=(\$url[\$k+6]<<16); case 6 : \$b+=(\$url[\$k+5]<<8); case 5 : \$b+=(\$url[\$k+4]); case 4 : \$a+=(\$url[\$k+3]<<24); case 3 : \$a+=(\$url[\$k+2]<<16); case 2 : \$a+=(\$url[\$k+1]<<8); case 1 : \$a+=(\$url[\$k+0]); /* case 0: nothing left to add */ } \$mix = mix(\$a,\$b,\$c); /*-------------------------------------------- report the result */ return \$mix[2]; } //converts a string into an array of integers containing the numeric value of the char function strord(\$string) { for(\$i=0;\$i=2.0.114:\t6%u\n",\$ch); ?>``` Any idea what is still wrong?
 09-15-2004, 10:24 AM #183 gprm Junior Member   Posts: 2 Karma: 10 Join Date: Sep 2004 The critical point is this \$prbuf array. It should be an array of unsigned int (32bit). so if you have twenty unsigned int, it's hashed as 20*4=80 bytes (8 bit) I don't think your strord(\$prbuf) is doing well here. Only suggestions as I'm quite ignorant regarding type conversions in php.
 09-15-2004, 03:04 PM #184 traB I'll code for food   Posts: 4 Karma: 10 Join Date: Sep 2004 Yes, the point here is that you must translate \$prbuf into an array of 8 bit integers. I have modified your code, adding a function for doing that. It still doesn't work with all URLs, because the ***** php is not able to manage 32 bit unsigned integers , so the line \$ch = (((\$ch/7) << 2) | ((\$ch%13)&7)); doesn't work if \$ch >2147483647 (if \$ch has the bit 32 set to 1) I am looking after a way of solving that.. if anyone has any ideas.. Code: ```>1); \$a &= (~\$z); \$a |= 0x40000000; \$a = (\$a>>(\$b-1)); } else { \$a = (\$a>>\$b); } return \$a; } function mix(\$a,\$b,\$c) { \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,13)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<8); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,13)); \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,12)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<16); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,5)); \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,3)); \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<10); \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,15)); return array(\$a,\$b,\$c); } function GoogleCH(\$url, \$length=null, \$init=GOOGLE_MAGIC) { if(is_null(\$length)) { \$length = sizeof(\$url); } \$a = \$b = 0x9E3779B9; \$c = \$init; \$k = 0; \$len = \$length; while(\$len >= 12) { \$a += (\$url[\$k+0] +(\$url[\$k+1]<<8) +(\$url[\$k+2]<<16) +(\$url[\$k+3]<<24)); \$b += (\$url[\$k+4] +(\$url[\$k+5]<<8) +(\$url[\$k+6]<<16) +(\$url[\$k+7]<<24)); \$c += (\$url[\$k+8] +(\$url[\$k+9]<<8) +(\$url[\$k+10]<<16)+(\$url[\$k+11]<<24)); \$mix = mix(\$a,\$b,\$c); \$a = \$mix[0]; \$b = \$mix[1]; \$c = \$mix[2]; \$k += 12; \$len -= 12; } \$c += \$length; switch(\$len) /* all the case statements fall through */ { case 11: \$c+=(\$url[\$k+10]<<24); case 10: \$c+=(\$url[\$k+9]<<16); case 9 : \$c+=(\$url[\$k+8]<<8); /* the first byte of c is reserved for the length */ case 8 : \$b+=(\$url[\$k+7]<<24); case 7 : \$b+=(\$url[\$k+6]<<16); case 6 : \$b+=(\$url[\$k+5]<<8); case 5 : \$b+=(\$url[\$k+4]); case 4 : \$a+=(\$url[\$k+3]<<24); case 3 : \$a+=(\$url[\$k+2]<<16); case 2 : \$a+=(\$url[\$k+1]<<8); case 1 : \$a+=(\$url[\$k+0]); /* case 0: nothing left to add */ } \$mix = mix(\$a,\$b,\$c); /*-------------------------------------------- report the result */ return \$mix[2]; } //converts a string into an array of integers containing the numeric value of the char function strord(\$string) { for(\$i=0;\$i=2.0.114:\t6%u\n",\$ch); ?>``` Regards, traB Last edited by traB; 09-15-2004 at 03:09 PM. Reason: Clarifying...
 09-15-2004, 07:14 PM #185 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 I imagine something like the solution used in zeroFill to fix shift right may work.
 09-15-2004, 07:17 PM #186 traB I'll code for food   Posts: 4 Karma: 10 Join Date: Sep 2004 Done! Woking PHP code for new checksum is: PHP Code: ``` >1);             \$a &= (~\$z);             \$a |= 0x40000000;             \$a = (\$a>>(\$b-1));         }         else         {             \$a = (\$a>>\$b);         }         return \$a; }  function mix(\$a,\$b,\$c) {   \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,13));    \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<8);    \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,13));   \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,12));   \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<16);   \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,5));    \$a -= \$b; \$a -= \$c; \$a ^= (zeroFill(\$c,3));     \$b -= \$c; \$b -= \$a; \$b ^= (\$a<<10);    \$c -= \$a; \$c -= \$b; \$c ^= (zeroFill(\$b,15));      return array(\$a,\$b,\$c); } function GoogleCH(\$url, \$length=null, \$init=GOOGLE_MAGIC) {     if(is_null(\$length)) {         \$length = sizeof(\$url);     }     \$a = \$b = 0x9E3779B9;     \$c = \$init;     \$k = 0;     \$len = \$length;     while(\$len >= 12) {         \$a += (\$url[\$k+0] +(\$url[\$k+1]<<8) +(\$url[\$k+2]<<16) +(\$url[\$k+3]<<24));         \$b += (\$url[\$k+4] +(\$url[\$k+5]<<8) +(\$url[\$k+6]<<16) +(\$url[\$k+7]<<24));         \$c += (\$url[\$k+8] +(\$url[\$k+9]<<8) +(\$url[\$k+10]<<16)+(\$url[\$k+11]<<24));         \$mix = mix(\$a,\$b,\$c);         \$a = \$mix[0]; \$b = \$mix[1]; \$c = \$mix[2];         \$k += 12;          \$len -= 12;     }     \$c += \$length;     switch(\$len)              /* all the case statements fall through */     {         case 11: \$c+=(\$url[\$k+10]<<24);         case 10: \$c+=(\$url[\$k+9]<<16);         case 9 : \$c+=(\$url[\$k+8]<<8);           /* the first byte of c is reserved for the length */         case 8 : \$b+=(\$url[\$k+7]<<24);         case 7 : \$b+=(\$url[\$k+6]<<16);         case 6 : \$b+=(\$url[\$k+5]<<8);         case 5 : \$b+=(\$url[\$k+4]);         case 4 : \$a+=(\$url[\$k+3]<<24);         case 3 : \$a+=(\$url[\$k+2]<<16);         case 2 : \$a+=(\$url[\$k+1]<<8);         case 1 : \$a+=(\$url[\$k+0]);          /* case 0: nothing left to add */     }     \$mix = mix(\$a,\$b,\$c);     /*-------------------------------------------- report the result */     return \$mix[2]; } //converts a string into an array of integers containing the numeric value of the char function strord(\$string) {     for(\$i=0;\$i=2.0.114:\t6%u\n",\$ch); ?> ``` I'll add new code as soon as possible to PR Monitor . Both checksums will be checked on this tool and will keep track of any diferences between results for the use of old and new checksum. Last edited by traB; 09-15-2004 at 10:19 PM.
09-15-2004, 07:20 PM   #187
traB
I'll code for food

Posts: 4
Karma: 10
Join Date: Sep 2004
Quote:
 Originally Posted by alexstapleton I imagine something like the solution used in zeroFill to fix shift right may work.
It comes to my mind, too.. but since PHP is using 64 bits for handling of floating point operations, I believe that (int)fmod(\$ch,13) instead \$ch%13 is safe enought.

 09-15-2004, 07:22 PM #188 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 could you not detect if the 32nd bit is 1 at \$ch = (((\$ch/7) << 2) | ((\$ch%13)&7)); and then set it to 0. and restore the CORRECT bit afterwards? you would need to calculate what that bit should be but it should work. i am of course assuming its generating the incorrect BINARY rather than incorect Decimal output at that point of course. as long as the binary value remains correct it does not matter if it is unsigned or not. \$ch = (((((int)(\$ch/7)) << 2) | ((\$ch%13)&7)); (int) may be needed if float based weirdness happens.
 09-15-2004, 07:23 PM #189 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 fmod ey, never seen that one before. well done! ill get the new code on my server and hook the PageRank fetcher up too it asap. sleep now
 09-15-2004, 07:30 PM #190 traB I'll code for food   Posts: 4 Karma: 10 Join Date: Sep 2004 Hehe.. thank you man Usually the answer is simpler than it seems to be. All the hard work was done by you, gprm, Morptheus, Doctorow... so I only had to take it and... Bingo ! If you find any bug let me now and we'll see what can do with it
 09-15-2004, 07:45 PM #191 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 looks like GPRM did most of the hard work on the new version wish I had more time for silly things like this these days
 09-15-2004, 08:13 PM #192 mosert Nameless Being congratulations guys ! level 2 successful. when will begin the level 3 ?
 09-16-2004, 12:27 AM #193 Ridolph Nameless Being Perl version again Hey, has anyone put together a perl version of the (old or new) code, or is that non-working example up above the only one? Tanks Ridolph
 09-16-2004, 01:42 PM #194 gemini Junior Member   Posts: 2 Karma: 10 Join Date: Sep 2004 Hello everyone, just wanted to say what a great team you are I am actually the guy who passed the original C script by Bob Jenkins to Cyberax (I didn't write it so there are no points for me). Since I'm not a programmer, but was looking for the same script in PHP i have a question: I know there is a way to check PR through the actual G-toolbar, and it would make more sense (since google changes its algo) - is there a way to do that in PHP? I guess it wouldn't be a problem to do it on ASP.Net ... what do you think about doing it on PHP? Also, I noticed this: I have 2.0.113 and 2.0.114 toolbars installed on different computers and 1) 2.0.113 shows PR 4 for http://www.c21myrtlebeach.com 2) 2.0.114 - PR5 for the same site. I run the script you guys wrote and it gives 2 different checksums as we know, but both XML files shows PR 5 Why is that? Try this tool http://www.top25web.com/pagerank.php for checking on http://c21myrtlebeach.com http://www.c21myrtlebeach.com and then you can check the same here http://www.ibsteam.net/gate.html?name=PageRank I've both checksums and PRs showing from old script and new one as you wrote.... kinda strange Thank you very much for all your hard work P.S. Vijay (Cyberax) gave me the link to the forum - thanks Vijay .
 09-16-2004, 07:36 PM #195 alexstapleton Enthusiast   Posts: 49 Karma: 123 Join Date: Jun 2004 you could probably write a PHP module to hook into the googlebar.dll but it would be platform dependant (e.g. only run on windows or WINE) which isnt exactly ideal is it.