computeNAF static method
Compute the Non-Adjacent Form (NAF) of a given integer.
Parameters:
mult
: The integer for which NAF is computed.
Returns:
- A list of BigInt values representing the NAF of the input integer.
Implementation
static List<BigInt> computeNAF(BigInt mult) {
List<BigInt> nafList = [];
while (mult != BigInt.zero) {
if (mult.isOdd) {
BigInt nafDigit = mult % BigInt.from(4);
// Ensure that the NAF digit is within the range [-2, 2]
if (nafDigit >= BigInt.two) {
nafDigit -= BigInt.from(4);
}
nafList.add(nafDigit);
mult -= nafDigit;
} else {
nafList.add(BigInt.zero);
}
mult ~/= BigInt.two;
}
return nafList;
}