示例#1
0
        public void TestCompareTo()
        {
            ECFieldElement X1     = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1);
            ECFieldElement Y1     = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1);
            ECFieldElement X2     = new ECFieldElement(new BigInteger(300), ECCurve.Secp256k1);
            ECFieldElement Y2     = new ECFieldElement(new BigInteger(400), ECCurve.Secp256k1);
            ECFieldElement X3     = new ECFieldElement(new BigInteger(100), ECCurve.Secp256r1);
            ECFieldElement Y3     = new ECFieldElement(new BigInteger(400), ECCurve.Secp256r1);
            ECPoint        point1 = new ECPoint(X1, Y1, ECCurve.Secp256k1);
            ECPoint        point2 = new ECPoint(X2, Y1, ECCurve.Secp256k1);
            ECPoint        point3 = new ECPoint(X1, Y2, ECCurve.Secp256k1);
            ECPoint        point4 = new ECPoint(X3, Y3, ECCurve.Secp256r1);

            point1.CompareTo(point1).Should().Be(0);
            point1.CompareTo(point2).Should().Be(-1);
            point2.CompareTo(point1).Should().Be(1);
            point1.CompareTo(point3).Should().Be(-1);
            point3.CompareTo(point1).Should().Be(1);
            Action action = () => point3.CompareTo(point4);

            action.Should().Throw <InvalidOperationException>();
        }
示例#2
0
        public void Compare_Equal_Points()
        {
            // Arrange
            var pubkey_A = "0238356c74a1ab4d40df857b790e4232180e2f99f5c78468c150d0903a3e5d2b6f".HexToBytes();
            var pubkey_B = "0438356c74a1ab4d40df857b790e4232180e2f99f5c78468c150d0903a3e5d2b6fc88c3095b1b688d3d027477dfad0deb1ab94cb08db2de5abb79c1482aa1ea2fc".HexToBytes();
            var pointA   = new ECPoint(pubkey_A);
            var pointB   = new ECPoint(pubkey_B);

            // Act
            var result = pointA.CompareTo(pointB);

            // Assert
            Assert.AreEqual(0, result);
        }
示例#3
0
        public void Compare_Different_Points()
        {
            // Arrange
            var pubkey_A = "0238356c74a1ab4d40df857b790e4232180e2f99f5c78468c150d0903a3e5d2b6f".HexToBytes();
            var pubkey_B = "0324de2cc4fe4b20963a5bae8cdcd52f431cd08ab331197e70e1d66d94ff35dda2".HexToBytes();
            var point_A  = new ECPoint(pubkey_A);
            var point_B  = new ECPoint(pubkey_B);

            // Act
            var result_A = point_A.CompareTo(point_B);
            var result_B = point_B.CompareTo(point_A);

            // Assert
            Assert.AreEqual(1, result_A);
            Assert.AreEqual(-1, result_B);
        }