{"ScriptPreparationCode":"var saltVal = crypto.getRandomValues(new Uint8Array(16));\r\n\r\nfunction arrayBufferToHexString(bytes) {\r\n bytes = new Uint8Array(bytes);\r\n var hex = new Array(bytes.length);\r\n for (let i = 0; i \u003C bytes.length; i\u002B\u002B) {\r\n hex[i] = (\u00220\u0022 \u002B bytes[i].toString(16)).slice(-2);\r\n }\r\n return hex.join(\u0022\u0022);\r\n}\r\n\r\nfunction bytesToHexString(bytes) {\r\n bytes = new Uint8Array(bytes);\r\n var hexBytes = [];\r\n for (var i = 0; i \u003C bytes.length; i\u002B\u002B) {\r\n var byteString = bytes[i].toString(16);\r\n if (byteString.length \u003C 2) byteString = \u00220\u0022 \u002B byteString;\r\n hexBytes.push(byteString);\r\n }\r\n return hexBytes.join(\u0022\u0022);\r\n}\r\n\r\nfunction buf2hex(buffer) { // buffer is an ArrayBuffer\r\n return [...new Uint8Array(buffer)]\r\n .map(x =\u003E x.toString(16).padStart(2, \u00270\u0027))\r\n .join(\u0027\u0027);\r\n}\r\n\r\nfunction hex(arrayBuffer)\r\n{\r\n \tconst asciiCodes = new Uint8Array(\r\n \tArray.prototype.map.call(\r\n \t\u00220123456789abcdef\u0022,\r\n \tchar =\u003E char.charCodeAt()\r\n \t)\r\n\t);\r\n \r\n const buff = new Uint8Array(arrayBuffer);\r\n const charCodes = new Uint8Array(buff.length * 2);\r\n\r\n for (let i = 0; i \u003C buff.length; \u002B\u002Bi)\r\n {\r\n charCodes[i * 2] = asciiCodes[buff[i] \u003E\u003E\u003E 4];\r\n charCodes[i * 2 \u002B 1] = asciiCodes[buff[i] \u0026 0xf];\r\n }\r\n\r\n return String.fromCharCode(...charCodes);\r\n}\r\n\r\nfunction hex2(arrayBuffer)\r\n{\r\n return Array.prototype.map.call(\r\n new Uint8Array(arrayBuffer),\r\n n =\u003E n.toString(16).padStart(2, \u00220\u0022)\r\n ).join(\u0022\u0022);\r\n}\r\n\r\nfunction arrayBufferToBase64(buffer) {\r\n const byteArray = new Uint8Array(buffer);\r\n const binaryString = byteArray.reduce((acc, byte) =\u003E acc \u002B String.fromCharCode(byte), \u0022\u0022);\r\n return btoa(binaryString);\r\n}\r\n\r\nfunction arrayBufferToBase64loop( buffer ) {\r\n var binary = \u0027\u0027;\r\n var bytes = new Uint8Array( buffer );\r\n var len = bytes.byteLength;\r\n for (var i = 0; i \u003C len; i\u002B\u002B) {\r\n binary \u002B= String.fromCharCode( bytes[ i ] );\r\n }\r\n return window.btoa( binary );\r\n}\r\n\r\nfunction bytesToHexString2(bytes) {\r\n bytes = new Uint8Array(bytes);\r\n var hexBytes = \u0027\u0027;\r\n for (var i = 0; i \u003C bytes.length; i\u002B\u002B) {\r\n var byteString = bytes[i].toString(16);\r\n if (byteString.length \u003C 2) byteString = \u00220\u0022 \u002B byteString;\r\n hexBytes \u002B= byteString;\r\n }\r\n return hexBytes;\r\n}\r\n\r\nfunction bytesToHexString3(bytes) {\r\n bytes = new Uint8Array(bytes);\r\n var hexBytes = \u0027\u0027;\r\n for (var i = 0; i \u003C bytes.length; i\u002B\u002B) {\r\n var byteString = bytes[i].toString(16);\r\n if (byteString.length \u003C 2) hexBytes \u002B= \u00220\u0022;\r\n hexBytes \u002B= byteString;\r\n }\r\n return hexBytes;\r\n}\r\n\r\nfunction bytesToHexString4(bytes) {\r\n bytes = new Uint8Array(bytes);\r\n var hexBytes = \u0027\u0027;\r\n for (var i = 0; i \u003C bytes.length; i\u002B\u002B) {\r\n hexBytes \u002B= bytes[i].toString(16).padStart(2, \u00270\u0027);\r\n }\r\n return hexBytes;\r\n}\r\n","TestCases":[{"Name":"directly set","Code":"arrayBufferToHexString(saltVal);","IsDeferred":false},{"Name":"push values","Code":"bytesToHexString(saltVal)","IsDeferred":false},{"Name":"buf2hex()","Code":"buf2hex(saltVal)","IsDeferred":false},{"Name":"precomputed ASCII with shift","Code":"hex(saltVal)","IsDeferred":false},{"Name":"array prototype map","Code":"hex2(saltVal)","IsDeferred":false},{"Name":"base64","Code":"arrayBufferToBase64(saltVal)","IsDeferred":false},{"Name":"base64 loop","Code":"arrayBufferToBase64loop(saltVal)","IsDeferred":false},{"Name":"string \u002B","Code":"bytesToHexString2(saltVal)","IsDeferred":false},{"Name":"string \u002B 2","Code":"bytesToHexString3(saltVal)","IsDeferred":false},{"Name":"string \u002B pad","Code":"bytesToHexString4(saltVal)","IsDeferred":false}]}