Adding the XOR function to the bigint library

I use this Big Integer library for Javascript: http://www.leemon.com/crypto/BigInt.js and I need to be able to XOR two large interfaces together and the sad library does not include such a function. The library is relatively simple, so I do not consider it a huge task, just confusing.

I tried to hack one, but not very lucky, I would be very grateful if someone could lend me a hand. This is what I tried (maybe wrong). But I assume that the structure will be very similar to some other functions there.

function xor(x, y)
{
    var c, k, i;
    var result = new Array(0); // big int for result

    k=x.length>y.length ? x.length : y.length; // array length of the larger num

    // Make sure result is the correct array size? maybe:
    result = expand(result, k); // ?

    for (c=0, i=0; i < k; i++)
    {
        // Do some xor here
    }

    // return the bigint xor result
    return result;
}

, , bigInt. , bigintC [i] = bigintA [i] ^ bigintB [i], , . .

+3
2

, js int bpe .

:

//convert the integer t into a bigInt with at least the given number of bits.
//the returned array stores the bigInt in bpe-bit chunks, little endian (buff[0] is least significant word)
//Pad the array with leading zeros so that it has at least minSize elements.
//There will always be at least one leading 0 element.
function int2bigInt(t,bits,minSize) {   
  var i,k;
  k=Math.ceil(bits/bpe)+1;
  k=minSize>k ? minSize : k;
  buff=new Array(k);
  copyInt_(buff,t);
  return buff;
}

:

// This code defines a bigInt library for arbitrary-precision integers.
// A bigInt is an array of integers storing the value in chunks of bpe bits, 
// little endian (buff[0] is the least significant word).

, , XOR .

, , , bigints , 2s-.

0

Source: https://habr.com/ru/post/1749246/


All Articles