Skip to content

Instantly share code, notes, and snippets.

@AlloVince
Last active December 20, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlloVince/6067579 to your computer and use it in GitHub Desktop.
Save AlloVince/6067579 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment