public static GenerateNaf ( BigInteger k ) : byte[] | ||
k | BigInteger | |
return | byte[] |
public static byte[] GenerateWindowNaf(int width, BigInteger k) { if (width == 2) { return(WNafUtilities.GenerateNaf(k)); } if (width < 2 || width > 8) { throw new ArgumentException("must be in the range [2, 8]", "width"); } if (k.SignValue == 0) { return(WNafUtilities.EMPTY_BYTES); } byte[] array = new byte[k.BitLength + 1]; int num = 1 << width; int num2 = num - 1; int num3 = num >> 1; bool flag = false; int num4 = 0; int i = 0; while (i <= k.BitLength) { if (k.TestBit(i) == flag) { i++; } else { k = k.ShiftRight(i); int num5 = k.IntValue & num2; if (flag) { num5++; } flag = ((num5 & num3) != 0); if (flag) { num5 -= num; } num4 += ((num4 > 0) ? (i - 1) : i); array[num4++] = (byte)num5; i = width; } } if (array.Length > num4) { array = WNafUtilities.Trim(array, num4); } return(array); }