diff --git a/app/js/lib/bin_utils.js b/app/js/lib/bin_utils.js index d59b2abe..d8a21b65 100644 --- a/app/js/lib/bin_utils.js +++ b/app/js/lib/bin_utils.js @@ -43,9 +43,15 @@ function bytesToHex (bytes) { function bytesFromHex (hexString) { var len = hexString.length, i, + start = 0, bytes = []; - for (i = 0; i < len; i += 2) { + if (hexString.length % 2) { + bytes.push(parseInt(hexString.charAt(0), 16)); + start++; + } + + for (i = start; i < len; i += 2) { bytes.push(parseInt(hexString.substr(i, 2), 16)); } @@ -575,7 +581,7 @@ function bytesModPow (x, y, m) { try { var xBigInt = str2bigInt(bytesToHex(x), 16), yBigInt = str2bigInt(bytesToHex(y), 16), - mBigInt = str2bigInt(bytesToHex(m), 16, 2), + mBigInt = str2bigInt(bytesToHex(m), 16), resBigInt = powMod(xBigInt, yBigInt, mBigInt); return bytesFromHex(bigInt2str(resBigInt, 16));