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

Go Back   MobileRead Forums > Miscellaneous > Lounge

Notices

Reply
 
Thread Tools Search this Thread
Old 09-15-2004, 06:34 AM   #181
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
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($prbuf800xe6359a60);

printf('CH: 6%u'$ch); 
alexstapleton is offline   Reply With Quote
Old 09-15-2004, 08: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:
<?php
/*
 		Written and contributed by
 		Alex Stapleton,
 		Andy Doctorow,
 		Tarakan,
 		Bill Zeller,
 		Vijay "Cyberax" Bhatter
    This code is released unto the public domain
*/
header("Content-Type: text/plain; charset=utf-8");
define('GOOGLE_MAGIC', 0xE6359A60);

//unsigned shift right
function zeroFill($a, $b)
{
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>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<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}
// http://www.example.com/ - Checksum: 6540747202
$url = 'info:'.$_GET['url'];
print("url:\t{$_GET['url']}\n");
$ch = GoogleCH(strord($url));
printf("Checksum <2.0.114:\t6%u\n",$ch);

// new since Toolbar 2.0.114
$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 = GoogleCH(strord($prbuf), 80); 
//

printf("Checksum >=2.0.114:\t6%u\n",$ch);
?>
Any idea what is still wrong?
  Reply With Quote
Advert
Old 09-15-2004, 09:24 AM   #183
gprm
Junior Member
gprm began at the beginning.
 
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.
gprm is offline   Reply With Quote
Old 09-15-2004, 02:04 PM   #184
traB
I'll code for food
traB began at the beginning.
 
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:
<?php
/*
 		Written and contributed by
 		Alex Stapleton,
 		Andy Doctorow,
 		Tarakan,
 		Bill Zeller,
 		Vijay "Cyberax" Bhatter
 		traB
    This code is released unto the public domain
*/
header("Content-Type: text/plain; charset=utf-8");
define('GOOGLE_MAGIC', 0xE6359A60);

//unsigned shift right
function zeroFill($a, $b)
{
    $z = hexdec(80000000);
        if ($z & $a)
        {
            $a = ($a>>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<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}


// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32

function c32to8bit($arr32) {
    for($i=0;$i<count($arr32);$i++) {
		for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
			$arr8[$bitOrder]=$arr32[$i]&255;
			$arr32[$i]=zeroFill($arr32[$i], 8);
		}	
    }
    return $arr8;
}


// http://www.example.com/ - Checksum: 6540747202
$url = 'info:'.$_GET['url'];
print("url:\t{$_GET['url']}\n");
$ch = GoogleCH(strord($url));
printf("Checksum <2.0.114:\t6%u\n",$ch);

// new since Toolbar 2.0.114
$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 = GoogleCH(c32to8bit($prbuf), 80); 
//

printf("Checksum >=2.0.114:\t6%u\n",$ch);
?>

Regards,
traB

Last edited by traB; 09-15-2004 at 02:09 PM. Reason: Clarifying...
traB is offline   Reply With Quote
Old 09-15-2004, 06:14 PM   #185
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
Posts: 49
Karma: 123
Join Date: Jun 2004
I imagine something like the solution used in zeroFill to fix shift right may work.
alexstapleton is offline   Reply With Quote
Advert
Old 09-15-2004, 06:17 PM   #186
traB
I'll code for food
traB began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2004
Done!

Woking PHP code for new checksum is:


PHP Code:
<?php
/*
         Written and contributed by
         Alex Stapleton,
         Andy Doctorow,
         Tarakan,
         Bill Zeller,
         Vijay "Cyberax" Bhatter
         traB
    This code is released into the public domain
*/
header("Content-Type: text/plain; charset=utf-8");
define('GOOGLE_MAGIC'0xE6359A60);

//unsigned shift right
function zeroFill($a$b)
{
    
$z hexdec(80000000);
        if (
$z $a)
        {
            
$a = ($a>>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 
$c+=($url[$k+8]<<8);
          
/* the first byte of c is reserved for the length */
        
case $b+=($url[$k+7]<<24);
        case 
$b+=($url[$k+6]<<16);
        case 
$b+=($url[$k+5]<<8);
        case 
$b+=($url[$k+4]);
        case 
$a+=($url[$k+3]<<24);
        case 
$a+=($url[$k+2]<<16);
        case 
$a+=($url[$k+1]<<8);
        case 
$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<strlen($string);$i++) {
        
$result[$i] = ord($string{$i});
    }
    return 
$result;
}


// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32

function c32to8bit($arr32) {
    for(
$i=0;$i<count($arr32);$i++) {
        for (
$bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
            
$arr8[$bitOrder]=$arr32[$i]&255;
            
$arr32[$i]=zeroFill($arr32[$i], 8);
        }    
    }
    return 
$arr8;
}


// http://www.example.com/ - Checksum: 6540747202
$url 'info:'.$_GET['url'];
print(
"url:\t{$_GET['url']}\n");
$ch GoogleCH(strord($url));
printf("Checksum <2.0.114:\t6%u\n",$ch);

$ch=sprintf("%u"$ch);
// new since Toolbar 2.0.114

$ch = ((($ch/7) << 2) | (((int)fmod($ch,13))&7));

$prbuf = array();
$prbuf[0] = $ch;
for(
$i 1$i 20$i++) {
      
$prbuf[$i] = $prbuf[$i-1]-9;
}
$ch GoogleCH(c32to8bit($prbuf), 80); 
//

printf("Checksum >=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 09:19 PM.
traB is offline   Reply With Quote
Old 09-15-2004, 06:20 PM   #187
traB
I'll code for food
traB began at the beginning.
 
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.
traB is offline   Reply With Quote
Old 09-15-2004, 06:22 PM   #188
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
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.
alexstapleton is offline   Reply With Quote
Old 09-15-2004, 06:23 PM   #189
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
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
alexstapleton is offline   Reply With Quote
Old 09-15-2004, 06:30 PM   #190
traB
I'll code for food
traB began at the beginning.
 
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
traB is offline   Reply With Quote
Old 09-15-2004, 06:45 PM   #191
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
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
alexstapleton is offline   Reply With Quote
Old 09-15-2004, 07:13 PM   #192
mosert
Nameless Being
 
congratulations guys ! level 2 successful. when will begin the level 3 ?
  Reply With Quote
Old 09-15-2004, 11:27 PM   #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
  Reply With Quote
Old 09-16-2004, 12:42 PM   #194
gemini
Junior Member
gemini began at the beginning.
 
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 .
gemini is offline   Reply With Quote
Old 09-16-2004, 06:36 PM   #195
alexstapleton
Enthusiast
alexstapleton doesn't litteralexstapleton doesn't litter
 
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.
alexstapleton is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seriously thoughtful Dekker's Algorithm help. Catire Lounge 13 03-19-2010 10:03 AM
Bulk Pagerank Checker Script? SNaRe Lounge 2 10-22-2006 04:36 PM
Google Toolbar Pagerank Checksum Revealed! Alexander Turcic Lounge 5 02-17-2006 08:09 AM
Google Checksum CH calculator cyberax Lounge 2 08-17-2004 09:37 PM


All times are GMT -4. The time now is 10:54 AM.


MobileRead.com is a privately owned, operated and funded community.