diff --git a/src/util.js b/src/util.js index 25ba5cd0..a1d5c3d2 100644 --- a/src/util.js +++ b/src/util.js @@ -154,18 +154,10 @@ const util = { * @returns {String} Hexadecimal representation of the array. */ uint8ArrayToHex: function (bytes) { - const r = []; - const e = bytes.length; - let c = 0; - let h; - while (c < e) { - h = bytes[c++].toString(16); - while (h.length < 2) { - h = '0' + h; - } - r.push('' + h); - } - return r.join(''); + const hexAlphabet = '0123456789abcdef'; + let s = ''; + bytes.forEach(v => { s += hexAlphabet[v >> 4] + hexAlphabet[v & 15]; }); + return s; }, /** diff --git a/test/crypto/cipher/des.js b/test/crypto/cipher/des.js index e3a00285..8cfc03b5 100644 --- a/test/crypto/cipher/des.js +++ b/test/crypto/cipher/des.js @@ -80,7 +80,7 @@ export default () => describe('TripleDES (EDE) cipher test with test vectors fro expect(encr, 'vector with block ' + util.uint8ArrayToHex(testvectors[i][0]) + ' and key ' + util.uint8ArrayToHex(key) + ' should be ' + util.uint8ArrayToHex(testvectors[i][1]) + - ' != ' + util.uint8ArrayToHex(encr)).to.be.equal(util.uint8ArrayToString(testvectors[i][1])); + ' != ' + encr).to.be.equal(util.uint8ArrayToString(testvectors[i][1])); } done(); });