var stringToHex = function(str) { var hex, i; var result = "0x"; for (i = 0; i < str.length; i++) { hex = str.charCodeAt(i).toString(16); result += hex; } return result } var hexToString = function(hex) { var i; var hexes = hex.match(/.{1,2}/g) || []; var result = ""; for(i = 0; i < hexes.length; i++) { result += String.fromCharCode(parseInt(hexes[i], 16)); } return result; } module.exports = { stringToHex, hexToString }