void Crypt::ComputeMD5(unsigned char digest[16], void const* bytesIn, unsigned int inputLen) { MD5 md5; MD5Open(&md5); MD5Digest(&md5, bytesIn, inputLen); MD5Close(&md5, digest); }
/* return true if digest calculated */ int get_file_digest(const char * filename, Uint8 digest[16]) { MD5 md5; el_file_ptr file = NULL; file = el_open(filename); memset (digest, 0, 16); if (file == NULL) { LOG_ERROR("MD5Digest: Unable to open %s (%d)", filename, errno); return 0; } if (el_get_pointer(file) == NULL) { el_close(file); return 0; } MD5Open(&md5); MD5Digest(&md5, el_get_pointer(file), el_get_size(file)); MD5Close(&md5, digest); el_close(file); return 1; }
float get_bag_tilt(float pos_x, float pos_y, int bag_id, int map_x, int map_y) { char str[64]; MD5 md5; Uint8 digest[16]; memset(digest, 0, 16); safe_snprintf(str, 40, "%f%f%f%f%f", pos_x, pos_y, (float) bag_id, (float) map_x, (float) map_y); MD5Open(&md5); MD5Digest(&md5, str, strlen(str)); MD5Close(&md5, digest); // the sum of 5 cos operations can be between -5 and +5 // normalize them to -1.0 ... +1.0 // multiply with 15 (-15.0 ... +15.0 degrees) return ((cosf(digest[3]) + cosf(digest[4]) + cosf(digest[5]) + cosf( digest[6]) + cosf(digest[7])) / 5.0f) * 30; }
float get_bag_rotation(float pos_x, float pos_y, int bag_id, int map_x, int map_y) { char str[64]; MD5 md5; Uint8 digest[16]; memset(digest, 0, 16); safe_snprintf(str, 40, "%f%f%f%f%f", pos_x, pos_y, (float) bag_id, (float) map_x, (float) map_y); MD5Open(&md5); MD5Digest(&md5, str, strlen(str)); MD5Close(&md5, digest); // the sum of 5 sin operations can be between -5 and +5 // normalize them to -0.5 ... +0.5 // multiply with 360 (-180.0 ... +180.0 degrees) return ((sinf(digest[2]) + sinf(digest[3]) + sinf(digest[4]) + sinf( digest[5]) + sinf(digest[6])) / 10.0f) * 360; }
void MD5Sum::clear() { MD5Open(&md5_); }