Exemplo n.º 1
0
 def test_listPointGenerator(self):
     r = SystemRandom()
     for i in range(10):
         p = getRandPrime(5)
         while p <= 10:
             p = getRandPrime(5)
         e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
         for point in e.listPointGenerator():
             self.assertTrue(e.isInCurve(point))
Exemplo n.º 2
0
 def test_basePoint(self):
     r = SystemRandom()
     for i in range(10):
         p = getRandPrime(5)
         while p <= 10:
             p = getRandPrime(5)
         e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
         G = e.G
         self.assertTrue(e.isInCurve(G))
Exemplo n.º 3
0
 def test_sqrtmod(self):
     r = random.SystemRandom()
     for i in range(10):
         p = prime.getRandPrime(20)
         while p < 10:
             p = prime.getRandPrime(10)
         for j in range(100):
             a = r.randint(1, p - 1)
             x = prime.sqrtmod(a, p)
             if x:
                 self.assertTrue(x * x % p == a)
Exemplo n.º 4
0
 def test_sqrtmod(self):
     r = random.SystemRandom()
     for i in range(10):
         p = prime.getRandPrime(20)
         while p < 10:
             p = prime.getRandPrime(10)
         for j in range(100):
             a = r.randint(1, p - 1)
             x = prime.sqrtmod(a, p)
             if x:
                 self.assertTrue(x * x % p == a)
Exemplo n.º 5
0
 def test_add(self):
     r = SystemRandom()
     for i in range(10):
         p = getRandPrime(5)
         while p <= 10:
             p = getRandPrime(5)
         e = ecc.ECC(r.randint(1, 100), r.randint(1, 100), p)
         all_points = list(e.listPointGenerator())
         for j in range(100):
             point1 = r.choice(all_points)
             point2 = r.choice(all_points)
             point = e.add(point1, point2)
             self.assertEqual(e.isInCurve(point), True)
Exemplo n.º 6
0
 def test_inv(self):
     r = random.SystemRandom()
     for p in [prime.getRandPrime(10 + i) for i in range(10)]:
         self.assertEqual(prime.inv(1, p) % p, 1)
         self.assertEqual(prime.inv(p - 1, p) * (p - 1) % p, 1)
         for i in range(10):
             a = r.randint(1, p-1)
             self.assertEqual(prime.inv(a, p) * a % p, 1)
Exemplo n.º 7
0
 def test_inv(self):
     r = random.SystemRandom()
     for p in [prime.getRandPrime(10 + i) for i in range(10)]:
         self.assertEqual(prime.inv(1, p) % p, 1)
         self.assertEqual(prime.inv(p - 1, p) * (p - 1) % p, 1)
         for i in range(10):
             a = r.randint(1, p - 1)
             self.assertEqual(prime.inv(a, p) * a % p, 1)
Exemplo n.º 8
0
 def test_getRandPrime(self):
     for i in range(100):
         n = prime.getRandPrime(10 + i)
         self.assertTrue(prime.isPrime(n))
Exemplo n.º 9
0
 def test_getRandPrime(self):
     for i in range(100):
         n = prime.getRandPrime(10 + i)
         self.assertTrue(prime.isPrime(n))