First, you should use memcmp
which assumes fixed-sized array instead of strcmp
which assumes zero-terminated strings, since your hash may contain zeros.
Second, I don't know where answerString
comes from, but if you're doing a brute force search you're not sure to recover the original string, just a string which has the same MD5 hash. That may or may not bee enough for your purposes.
Otherwise, I'm not sure what's your problem:
#include <string.h>
static const char a[16] = {0x57, 0x50, 0x1a, 0xc7, 0xb9, 0xd5, 0x44, 0x0a, 0xde, 0xe8, 0xb3, 0xdd, 0x97, 0x09, 0x72, 0xcb};
static const char b[16] = {0x57, 0x50, 0x1a, 0xc7, 0xb9, 0xd5, 0x44, 0x0a, 0xde, 0xe8, 0xb3, 0xdd, 0x97, 0x09, 0x72, 0xcb};
return memcmp(a, b, 16); // => returns 0
Now, you mentionned printf
. I hope you're not doing printf(a)
? Because your hash is an array of char, or char*
which in C
unfortunately also happens to be the type of strings. But the crucial difference between the two is that C-strings are zero-terminated. That means that every function accepting a string, such as printf
or strlen
excepts its char*
input to be terminated by a 0
. If it's not the case it will dangerously scan the memory outside of your variable until it finds a 0 byte.