I know there are many opinions about pagerank these days but for a project I'm working on I use it as one of several key indicators so don't give me the old "pagerank is worthless" speech  Applause

Your typical pagerank query looks like this;;

Now most of this is a no brainer except the "ch=8ece91f4d" bit, that's the checksum. The 8 ap


 s to be static so the actual checksum can be represented as ch=8 + the actual calculated checksum. Now the code to do this is available in


  and Java form but I needed C++ so I ported bits of both and here is the end result.

The following is a little test rig that I made up (gpr.cpp), the important bit is the getCS() function which returns the checksum to append to "ch=8" in the URL.

// Written by TheDarkness

// Compile with;
//      g++ -Wall -O2 gpr.cpp -o gpr

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string getCS( string* url )
        string* google_hash =
                new string( "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer." );
        int key = 16909125;
        for( unsigned int i = 0; i < url->length(); ++i )
                key = key ^ (int)google_hash->at( i % google_hash->length() ) ^ (int)url->at( i );

                // BEWARE, possibly non portable, depends on signed/unsigned padding,
                // one's complement, two's complement, etc.
                key = ((unsigned)key)>>23|((unsigned)key)<<9;


        delete google_hash;

        ostringstream oss( "8" );
        oss.setf( ios::hex, ios::basefield );
        oss.width( 2 );
        oss.fill( '0' );
        oss << ( ((unsigned)key)>>(8&255) ) << (key&255);

        return oss.str();

int main( void )
        string* str = new string( "" );
        cout << getCS( str ) << endl;
        (*str) = "";
        cout << getCS( str ) << endl;
        delete str;
        return 0;


Have fun,


i don't use c++ but you reminded me to look for one in java. then i thought


  would be even better. then i found one in




Sweetness TD


nice one using streams, nice bit of code
use static_cast<unsigned int>(var) instead of (unsigned)
its safer Applause


Not putting you on the spot Monk but can you explain why? I'm a bit foggy in that area.



no worries dude i was just bein a code nazi lol

two reasons, firstly its a safer C++ way of doing things and secondly its damn ugly making you take more notice of why your actually doing the cast.

E.g. unsigned in most compilers will be an unsigned int, but it might not be, making it quite - not for this app really, but in general.

static_cast is used for swapping between basic types, int, unsigned int, char etc
dynamic_cast is for casting up inheritence hierarchies [theres a better way to explain that lol]
and reinterpret_cast casts between 2 completely different types.

there is also const_cast but thats BAAAAD! Applause

so instead of (class b*) you would do dynamic_cast<class b*>(a)
its just generally good etc n wotnot

hope that helped explain a bit lol Applause


quote author=m0nkeymafia link=topic=413.msg3143#msg3143 date=1188916966

E.g. unsigned in most compilers will be an unsigned int, but it might not be, making it quite - not for this app really, but in general.

lol, I worked out what you mean eventually  Applause

Still not sure what the exact difference between (unsigned int) and static_cast<unsigned int> is but I've gone with static_cast<unsigned int> anyway lol


the method i described is the C++ way of doing casts and is safer to use than (unsigned int)

heh yeah im bad at explaining things, i always miss out crucial bits of information Applause


Its cool man I appreciate the input. Don't think I don't.



never man its all good Applause

Perkiset's Place Home   Politics @ Perkiset's