def test_multiply_by_number(self): ec = EllipticCurve('A') a = ec.get_forming() for k in [-1233535, 1231, 0, -1, 1, 1231341]: self.assertTrue(ec.is_on_curve(ec.multiply_by_number(a, k))) mul = ec.multiply_by_number self.assertEqual(mul(mul(a, 10), 10), mul(a, 100)) self.assertEqual(mul(mul(a, 2), -3), mul(a, -6)) self.assertEqual(mul(mul(a, -4), 7), mul(a, -28)) self.assertEqual(ec.summ(mul(a, 123), mul(a, -122)), mul(a, 1)) ec = EllipticCurve('test') point = Point(3, 6) n_s = range(7) rights = [ Point(0, 1, 0), Point(3, 6), Point(80, 10), Point(80, 87), Point(3, 91), Point(0, 1, 0), Point(3, 6) ] for n, right in zip(n_s, rights): print(right) print(ec.multiply_by_number(point, n)) self.assertEqual(ec.multiply_by_number(point, n), right)
def test_correctness_of_parameters(self): ec = EllipticCurve('A') self.assertTrue(ec.is_on_curve(ec.get_forming())) ec = EllipticCurve('B') self.assertTrue(ec.is_on_curve(ec.get_forming()))
if __name__ == '__main__': # Get eliptic curve EC ec = EllipticCurve(a=A, b=B, fp=FP) logger.info('Elliptic curve: EC = {}'.format(ec)) logger.info('Staring point: S = {}'.format(S)) if len(argv) != 2: raise EllipticCurveException('Invalid input') # Get public key PK PK = Point.from_string(argv[1]) logger.info('Public key: PK = {}'.format(PK)) # Check whether starting point S is on the elliptic curve EC if ec.is_on_curve(S): logger.info('S is on the Elliptic curve') else: raise EllipticCurveException('S is not on the Elliptic curve') # Check whether public key PK is on the elliptic curve EC if ec.is_on_curve(PK): logger.info('PK is on the Elliptic curve') else: raise EllipticCurveException('PK is not on the Elliptic curve') # Let's look for the private key point = S SK = 1 while point != PK: