// As described on page 8 of RFC 8554 private BigInteger Coef(BitString S, int i, int w) { var resultlhs = new BitString(new BigInteger((1 << w) - 1)); var resultrhs = new BitString(S.MSBSubstring(i * w / 8 * 8, 8).ToPositiveBigInteger() >> (8 - (w * (i % (8 / w)) + w))); return(resultlhs.AND(resultrhs).ToPositiveBigInteger()); }
public static BitString Encode(EdPoint point, int b) { var encoding = new BitString(point.Y, b); var xBit = new BitString(point.X, b).GetLeastSignificantBits(1); var bytes = new byte[b / 8]; bytes[0] = 1 << 7; if (xBit.Equals(BitString.One())) { encoding = encoding.OR(new BitString(bytes)); } else { encoding = encoding.AND(new BitString(bytes).NOT()); } return(BitString.ReverseByteOrder(encoding)); // switch to little endian }