Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created December 16, 2009 09:51
Show Gist options
  • Save cheeaun/257720 to your computer and use it in GitHub Desktop.
Save cheeaun/257720 to your computer and use it in GitHub Desktop.
function to generate auth token from URL for goo.gl
var getGooglAuthToken = function(b){
var c = function(){
for (var l=0, m=0, ml=arguments.length; m<ml; m++) l = l + arguments[m] & 4294967295;
return l;
}
var d = function(l){
l = String(l > 0 ? l : l + 4294967296);
var m = l;
for (var o=0, n=false, p=m.length-1; p>=0; --p){
var q = Number(m.charAt(p));
if (n){
q *= 2;
o += Math.floor(q/10) + q % 10;
} else o += q;
n = !n;
}
m = o % 10;
o = 0;
if (m != 0){
o = 10 - m;
if (l.length % 2 == 1){
if (o % 2 == 1) o += 9;
o /= 2;
}
}
m = o + l;
return m;
}
var e = function(l){
for (var m=5381, o=0, ll=l.length; o<ll; o++) m = c(m << 5, m, l.charCodeAt(o));
return m;
}
var f = function(l){
for (var m=0, o=0, ll=l.length; o<ll; o++) m = c(l.charCodeAt(o), m << 6, m << 16, -m);
return m
}
var i = e(b);
i = i >> 2 & 1073741823;
i = i >> 4 & 67108800 | i & 63;
i = i >> 4 & 4193280 | i & 1023;
i = i >> 4 & 245760 | i & 16383;
h = f(b);
var k = (i >> 2 & 15) << 4 | h & 15;
k |= (i >> 6 & 15) << 12 | (h >> 8 & 15) << 8;
k |= (i >> 10 & 15) << 20 | (h >> 16 & 15) << 16;
k |= (i >> 14 & 15) << 28 | (h >> 24 & 15) << 24;
return '7' + d(k);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment