Skip to content

Instantly share code, notes, and snippets.

@cwage
Created June 22, 2013 21:06
Show Gist options
  • Save cwage/5842612 to your computer and use it in GitHub Desktop.
Save cwage/5842612 to your computer and use it in GitHub Desktop.
mystring base64tobinary(mystring source)
{
int i;
int index;
char base64[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *tmp;
char chunk[7] = "";
mystring result;
result.text[0] = '\0';
for (i = 0; i < source.length; i++)
{
tmp = strchr(base64, source.text[i]);
index = (int) (tmp - base64);
dectobinary(index, chunk);
strcat(result.text, chunk);
}
return result;
}
char* dectobinary(int source, char * result)
{
char *p = result;
int i, k;
for (i = 5; i >= 0; i--)
{
k = source >> i;
if (k & 1)
*p++ = '1';
else
*p++ = '0';
}
*p = '\0';
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment