Fixed bytesFromHex

This commit is contained in:
Igor Zhukov 2014-11-11 23:30:23 +03:00
parent f2a602b455
commit ff60c7d0b0

View File

@ -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));