MD5 now returns binary string format instead of hex

This commit is contained in:
Tankred Hase
2012-03-18 22:48:44 +11:00
parent 1d1e757153
commit b348ccc2ab
4 changed files with 41 additions and 9 deletions

View File

@@ -13,7 +13,9 @@
*/
function MD5(entree) {
return md5(entree);
var hex = md5(entree);
var bin = util.hex2bin(hex);
return bin;
}
function md5cycle(x, k) {

View File

@@ -33,6 +33,7 @@ var Util = function() {
}
return r.join('');
};
/**
* create hexstring from a binary
* @param str [String] string to convert
@@ -52,6 +53,19 @@ var Util = function() {
}
return r.join('');
};
/**
* create binary string from a hex encoded string
* @param str [String] hex string to convert
* @return [String] string containing the binary values
*/
this.hex2bin = function(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
};
/**
* creating a hex string from an binary array of integers (0..255)
* @param [Array[integer 0..255]] array to convert