The test code and results are as follows:
Php:
echo md5(file_get_contents('test.torrent'));//e699b0e7535cebc1b10de1613d6797fb
Python:
print hashlib.md5(open("test.torrent").read()).hexdigest()#7cc752c88ae69677afe59ee7c3300e9d
Javascript:
var dragAndDrop = function(){ if (!window.File || !window.FileList || !window.FileReader) { return false; } var ignoreDrag = function(e) { e.originalEvent.stopPropagation(); e.originalEvent.preventDefault(); } var drop = function(e) { ignoreDrag(e); var dt = e.originalEvent.dataTransfer; var droppedFiles = dt.files; $.each(droppedFiles, function(index, file) { decodeFile(file); }); } $('body') .on('dragenter', ignoreDrag) .on('dragover', ignoreDrag) .on('drop', drop);};var decodeFile = function(file) { var fileReader = new FileReader(); var fileData = fileReader.readAsBinaryString(file); fileReader.onload = function(){ var fileData = this.result; console.log(CryptoJS.MD5(fileData)); }}dragAndDrop(); //393fe44680d69ea00fd0a4a2fb3fa8c5
Reply content:
The test code and results are as follows:
Php:
echo md5(file_get_contents('test.torrent'));//e699b0e7535cebc1b10de1613d6797fb
Python:
print hashlib.md5(open("test.torrent").read()).hexdigest()#7cc752c88ae69677afe59ee7c3300e9d
Javascript:
var Draganddrop = function () {if (!window. File | | !window. FileList | | !window. FileReader) {return false; } var Ignoredrag = function (e) {e.originalevent.stoppropagation (); E.originalevent.preventdefault (); } var drop = function (e) {Ignoredrag (e); var dt = E.originalevent.datatransfer; var droppedfiles = dt.files; $.each (droppedfiles, function (index, file) {decodefile (file); }); } $ (' body '). On (' DragEnter ', Ignoredrag). On (' DragOver ', Ignoredrag). On (' drop ', drop);}; var decodefile = function (file) {var filereader = new FileReader (); var fileData = filereader.readasbinarystring (file); Filereader.onload = function () {var fileData = This.result; Console.log (CRYPTOJS.MD5 (fileData)); }}draganddrop (); 393FE44680D69EA00FD0A4A2FB3FA8C5
Depending on the information you added in the question comments, Python version 2 differs from the PHP version, which is easy to understand:
- Python 2 Opens the file in the default text mode , and theWindows API processes some characters, causing the read data to be inconsistent;
- The correct MD5 value is the one that PHP calculates.
file_get_contents
is a binary safe;
The correct Python 2 & 3 code is as follows:
hashlib.md5(open("test.torrent", 'rb').read()).hexdigest()
Cryptojs This thing is a third party. The questioner is not provided and therefore cannot be tested.
I did a bit of testing, two Python methods, a JavaScript approach, and a Linux shell command, and the MD5 are the same. PHP is not tested, but I believe it should be the same. Python method One:
import md5m = md5.new("xxx\n")print m.hexdigest()结果是:6de9439834c9147569741d3c9c9fc010
Python method Two:
import hashlibh = hashlib.md5("xxx\n")print h.hexdigest()结果也是:6de9439834c9147569741d3c9c9fc010
JavaScript MD5, I downloaded from this: http://www.myersdaily.org/joseph/javascript/md5.js, the 101th line has a syntax error, plus var. The result is the same as the result above.
Linux Shell:
md5sumxxx回车后按ctrl + D
The printed result is the same as above.