Tag Info

Hot answers tagged

15

I believe that the difference is that the Hash in v7 was hashing the quotation marks around the string, but the Hash in v8 does not. For example, in M7: In[1]:= Hash["test", "MD5"] Out[1]= 64111166190477440563271147919838643147 and in M8: In[1]:= Hash["\"test\"", "MD5"] Out[1]= 64111166190477440563271147919838643147 Therefore, I'd say that the M8 ...


8

As an alternative to the solution by @VLC / Mark Fisher, the following JLink code will compute the correct MD5 hash (as returned by V8 or Unix md5sum): Needs["JLink`"] LoadJavaClass["java.security.MessageDigest"]; md5[s_String] := JavaBlock @ Module[{d, b} , d = java`security`MessageDigest`getInstance["MD5"] ; d@update[JavaNew["java.lang.String", ...


8

Older Mathematica versions were including the enclosing quotes "" when generating the hash. To get rid of the quotation marks you can use the function below instead of the standard Hash function. The credit for the function goes to Mark Fisher. StringHash[string_String, type_: "MD5"] := Module[{stream, file, hash}, stream = OpenWrite[]; ...


7

IntegerString[Hash["363", "MD5"], 16] // StringLength (* 30 *) IntegerString[Hash["a", "MD5"], 16] // StringLength (* 31 *) Here's a whopper found Googlin': IntegerString[Hash["jk8ssl", "MD5"], 16,32] IntegerString[Hash["jk8ssl", "MD5"], 16] // StringLength (* 0000000018e6137ac2caab16074784a6 *) (* 24 *)


5

You need to import as "String", not "Binary". The latter returns a list of numbers, which is not exactly the same as the file contents (though there's a one-to-one mapping between the two) ... Think e.g. about the fact that integers in Mathematica can be arbitrarily large while byte values are between 0..255. "String" will return the file contents byte ...


3

I believe your general concern is largely unfounded as file caching is already used. Compare these timings performed in Mathematica 10.0.2: Quit[] (* fresh Kernel session *) FileHash["file.mx", #] & /@ {"MD5"} // AbsoluteTiming {0.422024, {258141117636363265815580588062419660198}} FileHash["file.mx", "MD5"] // AbsoluteTiming {0.090005, ...



Only top voted, non community-wiki answers of a minimum length are eligible