Page 1 of 1

Google PR checksum

Posted: Wed Mar 21, 2007 12:37 am
by Pantcho!!
Hello,

I am intrested to make a google PR checker.

It seems you have to encode your requested URL and only then you will get the PR of the page.

It is called google checksum, and it is included in the HTTP GET protocol request.

so i searched the net and found a javaScript and C# codes
But i am not an expert programmer and even few lines of code including Hex and bit shifting can make the code tottaly weird for me.

here are the codes

Java Script

Code: Select all

    var GPR_HASH_SEED = “Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE. Yes, I’m talking to you, scammer.”;


    var hash = “8″ + GPR_awesomeHash(page);

    function GPR_awesomeHash(value) {
    var kindOfThingAnIdiotWouldHaveOnHisLuggage = 16909125;
    for(var i = 0;i < value.length;i ++ ) {
    kindOfThingAnIdiotWouldHaveOnHisLuggage ^= GPR_HASH_SEED.charCodeAt(i % GPR_HASH_SEED.length) ^ value.charCodeAt(i);
    kindOfThingAnIdiotWouldHaveOnHisLuggage = kindOfThingAnIdiotWouldHaveOnHisLuggage >>> 23 | kindOfThingAnIdiotWouldHaveOnHisLuggage << 9}
    return GPR_hexEncodeU32(kindOfThingAnIdiotWouldHaveOnHisLuggage)}

    function GPR_hexEncodeU32(num) {
    var result = GPR_toHex8(num >>> 24);
    result += GPR_toHex8(num >>> 16 & 255);
    result += GPR_toHex8(num >>> 8 & 255);
    return result + GPR_toHex8(num & 255)}

    function GPR_toHex8(num) {
    return(num < 16 ? "0" : "") + num.toString(16)}
C#

Code: Select all

    public class pagerank
    {

        private string toHex8(uint num)
        {

            if(num<16) return "0"+String.Format("{0:x}",num);
            else return String.Format(”{0:x}”,num);

        }
        public string calculateChecksum(string url)
        {

            string stupidGoogleHash = “Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE. Yes, I’m talking to you, scammer.”;
            uint key = 16909125;

            for(int i=0; i < url.Length; i++) {

                key = (uint)key ^ (uint)(stupidGoogleHash[i%stupidGoogleHash.Length])^(uint)(url[i]);
                key = key>>23|key<<9;

            }return “8″+toHex8(key>>(8&255))+toHex8(key&255);

        }

    }
All this is taken from http://www.webmasterwords.com/google-pa ... cksum-in-c


Apperciate help in converting it to PB!

Thanks for your time people!

Posted: Wed Mar 21, 2007 4:43 pm
by Clutch
Here is a rough approximation of the Javascript version. I don't have a means of verifying the correct checksum, though a posted comment in the link you gave provided what is supposedly a correct one (8FDF03E58) given the URL 'http://office.microsoft.com/en-us/default.aspx', and this code matches that checksum.

Code: Select all

Procedure.s GPR_toHex8(num.l)
  hexNum$ = Hex(num)
  If Len(hexNum$) % 2 = 1
    hexNum$ = "0" + hexNum$
  EndIf
  ProcedureReturn hexNum$
EndProcedure

Procedure.s GPR_hexEncodeU32(num.q)
  result.s = GPR_toHex8(num >> 24 & 255)
  result.s + GPR_toHex8(num >> 16 & 255)
  result.s + GPR_toHex8(num >>  8 & 255)
  result.s + GPR_toHex8(num & 255)
  ProcedureReturn result
EndProcedure

Procedure.s GPR_awesomeHash(value.s)
  GPR_HASH_SEED.s = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer."
  
  kotaiwhohl.q = 16909125
  
  For i = 0 To Len(value) - 1
    ;For some reason, the character values needed to be placed into variables
    ;before the XOr'ing below, else it produced an incorrect result.
    ghs.l = Asc(Mid(GPR_HASH_SEED, (i % Len(GPR_HASH_SEED)) + 1, 1))
    vvl.l = Asc(Mid(value, i + 1, 1))
    kotaiwhohl ! ghs ! vvl
    kotaiwhohl = (kotaiwhohl >> 23) | ((kotaiwhohl << 9) & $FFFFFFFF)
  Next i

  ProcedureReturn "8" + GPR_hexEncodeU32(kotaiwhohl)
EndProcedure

Debug GPR_awesomeHash("http://office.microsoft.com/en-us/default.aspx")
Edit - Here's a more PureBasic-ized and easier to read (IMO) version:

Code: Select all

Macro Hex8(expr)
  RSet(Hex(expr), 2, "0")
EndMacro

Macro Hex32(expr)
  Hex8((expr) >> 24 & $FF) + Hex8((expr) >> 16 & $FF) + Hex8((expr) >> 8 & $FF) + Hex8((expr) & $FF)
EndMacro

Procedure.s GPRHash(url$)
  seed$   = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer."
  hash.q  = 16909125

  For i = 0 To Len(url$) - 1
    *s.Character = @seed$ + (i % Len(seed$))
    *u.Character = @url$ + i
    hash ! *s\c ! *u\c
    hash >> 23 | (hash << 9 & $FFFFFFFF)
  Next i
  
  ProcedureReturn "8" + Hex32(hash)
EndProcedure

Debug GPRHash("http://office.microsoft.com/en-us/default.aspx")
HTH,
Clutch

Posted: Thu Mar 22, 2007 9:39 am
by dige
If you trace the google toolbar page rank query, it looks like this:

Code: Select all

GET http://toolbarqueries.google.de/search?client=navclient-auto&googleip=O;209.85.129.147;359&iqrn=-I&orig=0PpGr&ie=UTF-8&oe=UTF-8&querytime=Ec&features=Rank:&q=info:http%3a%2f%2foffice%2emicrosoft%2ecom%2fen%2dus%2fdefault%2easpx&ch=792701239938 HTTP/1.1
Seems that ch=792701239938 is the checksumm - code? (hex: 90AD0282)

but using GPRHash() results: 8FDF03E58

or did I understand something wrongly?

Posted: Thu Mar 22, 2007 4:02 pm
by Clutch
@dige
I can't say I know that much about the process of getting Google's PageRank. The result of 8FDF03E58 was taken from a comment posted in the link provided by Pantcho above:
Comment by cadet354
2006-10-19 06:58:41
You script don’t work with long url.
For example:
http://office.microsoft.com/en-us/default.aspx
script returns ch=8fa303e5c, but correct result is 8fdf03e58(google toolbar for FF).
I searched the web for 'googe pagerank checksum' and found several different algorithms giving various results. The one above generates a 4-byte hash and prepends an "8". Another I saw generates a 5-byte hash and prepends a "6". I then found a link to try the direct query to Google
Sending the result of GPRHash("http://office.microsoft.com/en-us/default.aspx") to retrieve the PageRank returns "Rank_1:1:8" from the server. I modified one byte of the hash in the link and received as a response a Google page detailing an error as well as their terms of service. I tried the link with two other sites and the results from GPRHash() and was returned 'Rank_1:1:n' both times. I haven't tested any of the hashes generated by any of the other online sources, and as I'm guessing that it works, I've been too lazy to find out anything further. :)

Posted: Thu Mar 22, 2007 4:18 pm
by dige
Could you post a snipped, how to get the page rank?

Posted: Thu Mar 22, 2007 4:45 pm
by Clutch
I had only done the testing by typing the address into the browser, but I suppose this would do it:

Code: Select all

Macro Hex8(expr) 
  RSet(Hex(expr), 2, "0") 
EndMacro 

Macro Hex32(expr) 
  Hex8((expr) >> 24 & $FF) + Hex8((expr) >> 16 & $FF) + Hex8((expr) >> 8 & $FF) + Hex8((expr) & $FF) 
EndMacro 

Procedure.s GPRHash(url$) 
  seed$   = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer." 
  hash.q  = 16909125 

  For i = 0 To Len(url$) - 1 
    *s.Character = @seed$ + (i % Len(seed$)) 
    *u.Character = @url$ + i 
    hash ! *s\c ! *u\c 
    hash >> 23 | (hash << 9 & $FFFFFFFF) 
  Next i 
  
  ProcedureReturn "8" + Hex32(hash) 
EndProcedure 

Procedure.s GetWebpage(URL$)
  Shared hInet.l

  If (hInet)
    hFile = InternetOpenUrl_(hInet, @URL$, #Null, 0, $80000000, #Null)
    If (hFile)
      chunk$ = Space(1024)
      Repeat
        ret = InternetReadFile_(hFile, @chunk$, 1024, @numRead)
        buffer$ + Left(chunk$, numRead)
      Until (numRead = 0)
      InternetCloseHandle_(hFile)
    EndIf
  EndIf
  ProcedureReturn buffer$
EndProcedure

Procedure.s GetPageRank(page$)
  If (page$)
    query$ = "http://www.google.com/search?client=navclient-auto&ch="
    query$ + GPRHash(page$) + "&features=Rank&q=info:" + page$
    
    pageRank$ = GetWebpage(query$)
  EndIf
  
  ProcedureReturn StringField(pageRank$, 3, #LF$)
EndProcedure

hInet.l = InternetOpen_("PBAGENT/1.0", 0, #Null, #Null, 0)

If (hInet)
  Debug GetPageRank("http://office.microsoft.com/en-us/default.aspx")
  
  InternetCloseHandle_(hInet)
  hInet = 0
EndIf

Posted: Thu Mar 22, 2007 4:47 pm
by thefool
Mr clutch; why do you think pantcho!! is a scammer?

Posted: Thu Mar 22, 2007 5:24 pm
by dige
@TheFool: you're joking?

@Clutch: seems to work :D thank you!

Posted: Thu Mar 22, 2007 5:25 pm
by thefool
dige wrote:@TheFool: you're joking?

Code: Select all

  seed$   = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer." 
i know pantcho!! quite well..

Posted: Thu Mar 22, 2007 6:16 pm
by Clutch
@thefool

:lol:
Pantcho is a scammer by his own admission. I'm just echoing his sentiment:
Pantcho!! wrote:...

Code: Select all

var GPR_HASH_SEED = “Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE. Yes, I’m talking to you, scammer.”;
@dige

You're welcome. :)

Posted: Thu Mar 22, 2007 6:23 pm
by thefool
:lol:

Sorry for that :p

Nice code, btw!

Posted: Thu Mar 22, 2007 6:27 pm
by Clutch
Thanks! :)

Posted: Sat Mar 24, 2007 4:39 pm
by Pantcho!!
WOW :shock:

thanks for that!! the code works very well!

apperciate your help man!

thanks a lot :)

Posted: Mon Mar 26, 2007 3:45 pm
by Clutch
You're welcome! :)

Posted: Sun May 06, 2007 4:01 pm
by Pantcho!!
Hi all

Again i want to thank Clutch for helping a lot!

2nd i found a little problem mayne someone knows why

when i run the code on this kind of URLS

http://technorati.com/tag/bass+fishing

all the URLS that contains "&" "+" "?" "=" are getting errors with google like the hash calculation is totaly wrong.

i tired using escape codes with the % numbers and it didnt work.

if anyone knows what might be the problem... thanks!
[/b]