decodePointHex method

ECPointFp? decodePointHex(
  1. String s
)

Implementation

ECPointFp? decodePointHex(String s) {
  switch (int.parse(s.substring(0, 2), radix: 16)) {
    case 0:
      return infinity;
    case 2:
    case 3:
      final x = fromBigInteger(BigInt.parse(s.substring(2), radix: 16));
      var y = fromBigInteger(x
          .multiply(x.square())
          .add(x.multiply(a))
          .add(b)
          .toBigInteger()
          .modPow(q ~/ BigInt.from(4) + BigInt.one, q));

      /* var y = x
          .multiply(x.square())
          .add(x.multiply(a.add(b)))
          .toBigInteger()
          .modPow(q ~/ BigInt.from(4) + BigInt.one, q);*/
      if (y.toBigInteger() % BigInt.two !=
          BigInt.parse(s.substring(0, 2), radix: 16) - BigInt.two) {
        y = y.negate();
      }
      return ECPointFp(this, x, y);
    case 4:
    case 6:
    case 7:
      final len = (s.length - 2) ~/ 2;
      final xHex = s.substring(2, 2 + len);
      final yHex = s.substring(2 + len, 2 + 2 * len);
      /*print("xHex: ${BigInt.parse(xHex, radix: 16).toRadixString(16)}");
      print("yHex: ${BigInt.parse(yHex, radix: 16).toRadixString(16)}");*/
      return ECPointFp(this, fromBigInteger(BigInt.parse(xHex, radix: 16)),
          fromBigInteger(BigInt.parse(yHex, radix: 16)));
    default:
      return null;
  }
}