From 23ce924d3af5f32dd1a0f25ca8fbc52970812aca Mon Sep 17 00:00:00 2001 From: fruiz500 Date: Fri, 5 Jun 2015 11:54:52 -0500 Subject: [PATCH] improved padLeft function The original padLeft function sometimes fails to pad the string on iPad, for reasons unknown. This one works. --- secrets.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/secrets.js b/secrets.js index 29bd08f..bc7548c 100644 --- a/secrets.js +++ b/secrets.js @@ -446,8 +446,8 @@ function split(str, padLength){ // Pads a string `str` with zeros on the left so that its length is a multiple of `bits` function padLeft(str, bits){ bits = bits || config.bits - var missing = str.length % bits; - return (missing ? new Array(bits - missing + 1).join('0') : '') + str; + while(str.length % bits) str = '0' + str; + return str; }; function hex2bin(str){ @@ -529,4 +529,4 @@ exports.hex2str = function(str, bytesPerChar){ // by default, initialize without an RNG exports.init(); -})(typeof module !== 'undefined' && module['exports'] ? module['exports'] : (window['secrets'] = {}), typeof GLOBAL !== 'undefined' ? GLOBAL : window ); \ No newline at end of file +})(typeof module !== 'undefined' && module['exports'] ? module['exports'] : (window['secrets'] = {}), typeof GLOBAL !== 'undefined' ? GLOBAL : window );