Skip to content

Instantly share code, notes, and snippets.

@n3rd
Last active August 12, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n3rd/58ef1f208fd2449c4fc3bf114c107e76 to your computer and use it in GitHub Desktop.
Save n3rd/58ef1f208fd2449c4fc3bf114c107e76 to your computer and use it in GitHub Desktop.
Base10ToBase64Url
public static string Base10ToBase64Url(ulong base10)
{
char[] base64url = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".ToCharArray();
var res = new List<char>();
for (ulong remainder = base10, mod = remainder % 64; remainder > 0; remainder = remainder / 64, mod = remainder % 64)
{
res.Add(base64url[mod]);
}
res.Reverse();
return new String(res.ToArray());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment