Skip to content

Instantly share code, notes, and snippets.

@sunils34
Created December 27, 2011 04:12
Show Gist options
  • Save sunils34/1522686 to your computer and use it in GitHub Desktop.
Save sunils34/1522686 to your computer and use it in GitHub Desktop.
base58_decode. - Decode Flickr shortened URLs
//Given a base58 encoded string, obtain the base 10 number.
//This is useful for decoding shortened flickr urls.
function base58_decode( snipcode )
{
var alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' ;
var num = snipcode.length ;
var decoded = 0 ;
var multi = 1 ;
for ( var i = (num-1) ; i >= 0 ; i-- )
{
decoded = decoded + multi * alphabet.indexOf( snipcode[i] ) ;
multi = multi * alphabet.length ;
}
return decoded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment