Created
April 22, 2009 16:40
-
-
Save itszero/99900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
using namespace std; | |
char* md5(char* str) | |
{ | |
char cmd[500]; | |
sprintf(cmd, "echo -n \"%s\" | md5sum", str); | |
FILE *fd = popen(cmd, "r"); | |
char *hash = (char*)malloc(sizeof(char) * 33); | |
hash[32] = NULL; | |
fread(hash, sizeof(char), 32, fd); | |
pclose(fd); | |
return hash; | |
} | |
int main() | |
{ | |
printf("MD5 of HelloWorld: %s\n", md5("HelloWorld")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment