This MATLAB version MD5 is for checksum of files and strings. The speed is very fast. A timer shows time taken to finish the process in seconds.
Just type: mMD5('filename') for a file or mMD5('string') for a string, eg., mMD5('abcd').
Reference: Tian-tai Huynh, MD5 in C
Hi there , Could you please tell how to run this file in MATLAB, I downloaded it as an mMD5.c (c script file !) not .m file!
is it can use for MATLAB R2014a ?
This function tries to open a file with the name given in the inputs. If the opening fails, the input is interpreted as a string. You cannot determine directly, if the hash has been created for the string or the file. So the reply depends on the current folder. This can be called random.
The mentioned bugs are serious.
there is a bug in this procedure, the last byte of the binary C-string is not set to zero, causing the procedure to return random length string. On some systems it might work OK, on others it might crash.
The fix is to change few last lines to enforce zero at the last byte:
change the line:
output = mxCalloc(32, sizeof(char));
output = mxCalloc(33, sizeof(char));
/* call the C subroutine */
output=(char)0; // FIX HERE
plhs = mxCreateString(output);
This produces incorrect MD5 check sums. When I create a random array and save it to a MAT file, your function gives a different checksum than the system-supplied checksum command on both Mac OS X and Ubuntu Linux (and both of them agree with each other).
There are several problems with this function:
1. printf statements are used rather than mexPrintf.
2. The output char array needs to be 1 greater in length.
3. Memory allocated to the output char array is deallocated before the function exits.
If anyone would like a working version, feel free to message me.
I've compiled this in r2009a under Vista 32bit using lcc.
I'm getting a segfault nearly everytime I call this:
The process takes 0 seconds
MEMORY BLOCK INTEGRITY FAILURE: ptr = 0x1F39FD40 caller = free(ptr)
Data has been written off the end of a memory block.
This block of memory has already been freed.
The size of the array was 32 bytes.
The value of the free counter is count = 288020,
alloc counter in header of memory block = 384563.
I am getting core dump after I run an excel file through the algorithm. Any suggestions as to why that is the case?
Great! It compiles with no problems (WinXP, R2008a, Visual C++), and runs very quickly.
It's just as fast as external MD5 programs, for instance MD5deep.exe on WinXP, and produces identical results.
This function is really great... It had saved my lot of work
For those not familiar with c-mex functions: type "mex mMD5" to compile before use. Also works with LCC (MSVC not necessary).
It really works very fast! Thanks a lot.
Great tool! Thanks.
I would like to get the MD5 sum returned as a matlab string argument.
Also I would like to be able to call the function incrementially so that the md5sum could be computed over many variables.
That is a good point to have the MD5 sum output stored in a string. The file has been updated. To use this function, just do:
The file has been updated to save the MD5 sum in a variable. For example:
% for a file
% for a string