Skip to content

Instantly share code, notes, and snippets.

@rintaun
Forked from anonymous/pagerank.php
Created April 24, 2012 14:12
Show Gist options
  • Save rintaun/2480010 to your computer and use it in GitHub Desktop.
Save rintaun/2480010 to your computer and use it in GitHub Desktop.
Hashing algoriths for Page Rank
<?php
// Function d checks
function d($a, $b) {
//$c = intval(8E7, 16);//80000000
$c = 2147483648;
$a = $a & 0xffffffff;
if ($c & $a) {
$a >>= 1;
$a &= ~$c;
$a = $a | 1073741824;
$a >>= $b - 1;
}
else $a >>= $b;
return $a;
}
// function g checks
function g($a, $b, $c) {
$a -= $b;
$a -= $c;
$a ^= d($c, 13);
$b -= $c;
$b -= $a;
$b ^= $a << 8;
$c -= $a;
$c -= $b;
$c ^= d($b, 13);
$a -= $b;
$a -= $c;
$a ^= d($c, 12);
$b -= $c;
$b -= $a;
$b ^= $a << 16;
$c -= $a;
$c -= $b;
$c ^= d($b, 5);
$a -= $b;
$a -= $c;
$a ^= d($c, 3);
$b -= $c;
$b -= $a;
$b ^= $a << 10;
$c -= $a;
$c -= $b;
$c ^= d($b, 15);
$a = $a & 0xffffffff;
$b = $b & 0xffffffff;
$c = $c & 0xffffffff;
$ret = array($a, $b, $c);
return $ret;
}
function a($a) {
$length = count($a);
$b = 2654435769;
$c = 2654435769;
$d = 3862272608;
$e = 0;
$h = array();
for ($f = $length; $f >= 12;) {
$b += $a[$e + 0] + ($a[$e + 1] << 8) + ($a[$e + 2] << 16) + ($a[$e + 3] << 24);
$c += $a[$e + 4] + ($a[$e + 5] << 8) + ($a[$e + 6] << 16) + ($a[$e + 7] << 24);
$d += $a[$e + 8] + ($a[$e + 9] << 8) + ($a[$e + 10] << 16) + ($a[$e + 11] << 24);
$h = g($b, $c, $d);
$b = $h[0];
$c = $h[1];
$d = $h[2];
$e += 12;
$f -= 12;
}
$d += $length;
switch ($f) {
case 11:
$d += $a[$e + 10] << 24;
case 10:
$d += $a[$e + 9] << 16;
case 9:
$d += $a[$e + 8] << 8;
case 8:
$c += $a[$e + 7] << 24;
case 7:
$c += $a[$e + 6] << 16;
case 6:
$c += $a[$e + 5] << 8;
case 5:
$c += $a[$e + 4];
case 4:
$b += $a[$e + 3] << 24;
case 3:
$b += $a[$e + 2] << 16;
case 2:
$b += $a[$e + 1] << 8;
case 1:
$b += $a[$e];
}
$h = g($b, $c, $d);
return $h[2] < 0 ? ((4294967296 + $h[2]) & 0xffffffff) : $h[2];
}
//function b checks
function b($a) {
$b = array();
for ($i = 0; $i < strlen($a); $i++)
$b[$i] = ord($a[$i]);
return $b;
}
function makehash ($f) {
$g = b("info:" . $f);
return a($g);
}
function googlePageRank($f) {
return "http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=6" . makehash($f) . "&features=Rank&q=info:" . $f;
// d = new XMLHttpRequest;
// d.open("GET", f, !1);
// d.send(null);
// return d.responseText.substr(9, 2).replace(/\s$/, "")
}
$_GET['url'] = "www.rentjungle.com";
$url = googlePageRank($_GET['url']);
?>
<a href="<?php echo $url?>"><?php echo $url?></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment