def test_curve_is_point_on_curve_functional_2(self): my_curve = curve(14, 19, 3623) P = (6, 730) Q = (3513, 2669) on_curve = my_curve.is_point_on_curve(Q) expected_on_curve = True self.assertEqual(on_curve, expected_on_curve)
def test_ecc_dlog_bsgs_functional_3(self): E = curve(8, 7, 73) P = (32, 53) R = (58, 4) n = ecc_dlog_bsgs(P, R, E) print("n: " + str(n)) self.assertEqual(n, 28)
def test_brute_ecc_dlog_functional_4(self): E = curve(8, 7, 73) P = (32, 53) R = (35, 47) n = ecc_dlog_brute(P, R, E) print("n: " + str(n)) self.assertEqual(n, 37)
def test_curve_is_point_on_curve_functional_4(self): my_curve = curve(14, 19, 3623) P = (6, 730) Q = (3, 345) on_curve = my_curve.is_point_on_curve(Q) expected_on_curve = False self.assertEqual(on_curve, expected_on_curve)
def test_curve_multiply_functional_3(self): my_curve = curve(8, 7, 73) P = (32, 53) P2 = my_curve.multiply(P, 11) expected_P2 = (39, 17) print("P2: " + str(P2)) self.assertEqual(P2, expected_P2)
def test_curve_multiply_functional_2(self): my_curve = curve(14, 19, 3623) P = (6, 730) P2 = my_curve.multiply(P, 947) expected_P2 = (3492, 60) print("P2: " + str(P2)) self.assertEqual(P2, expected_P2)
def test_curve_multiply_functional_1(self): my_curve = curve(3, 8, 13) P = (9, 7) P2 = my_curve.multiply(P, 2) expected_P2 = (9, 6) print("P2: " + str(P2)) self.assertEqual(P2, expected_P2)
def test_curve_add_functional_2(self): my_curve = curve(3, 8, 13) P = (9, 7) P2 = my_curve.add(P, P) expected_P2 = (9, 6) print("P2: " + str(P2)) self.assertEqual(P2, expected_P2)
def test_brute_ecc_dlog_functional_1(self): print("\n\nRunning test for ecc cryptanalysis module: ecc_dlog_brute") E = curve(8, 7, 73) P = (32, 53) R = (39, 17) n = ecc_dlog_brute(P, R, E) print("n: " + str(n)) self.assertEqual(n, 11)
def test_curve_add_functional_3(self): my_curve = curve(3, 8, 13) P = (9, 7) Q = (None, None) R = my_curve.add(P, Q) expected_R = P print("R: " + str(R)) self.assertEqual(R, expected_R)
def test_ecc_dlog_bsgs_functional_1(self): print("\n\nRunning test for cryptanalysis module: ecc_dlog_bsgs") E = curve(8, 7, 73) P = (32, 53) R = (39, 17) n = ecc_dlog_bsgs(P, R, E) print(E.multiply(P, 43)) print("n: " + str(n)) self.assertEqual(n, 11)
def test_curve_is_point_on_curve_functional_1(self): my_curve = curve(14, 19, 3623) P = (6, 730) Q = P points = [] points.append(Q) for i in range(1, 3623): Q = my_curve.add(P, Q) points.append(Q)
def test_curve_add_functional_1(self): print("\n\nRunning test for ecc src module: curve") my_curve = curve(3, 8, 13) P = (9, 7) Q = (1, 8) expected_R = (2, 10) R = my_curve.add(P, Q) print("R: " + str(R)) self.assertEqual(R, expected_R)
def test_ecc_diffie_1(self): P = (920, 303) E = curve(324, 1287, 3851) diffie_A = ecc_diffie_hellman(E, P) QA = diffie_A.public_keygen(private_key=1194) diffie_B = ecc_diffie_hellman(E, P) QB = diffie_B.public_keygen(private_key=1759) key_A = diffie_A.symmetric_keygen(QB, output_type = "whole point") key_B = diffie_B.symmetric_keygen(QA, output_type = "whole point") self.assertEqual(key_A, key_B)
def test_ecc_el_gammal_cipher(self): print("\n\nRunning test for ecc cipher class: ecc_el_gammal") P = (920, 303) E = curve(324, 1287, 3851) orig_plaintext = 555 BobEG1 = ecc_el_gammal(E, P) BobEG1.private_keygen() BobPub = BobEG1.public_keygen() AliceEG1 = ecc_el_gammal(E, P) AliceEG1.private_keygen() AlicePub = AliceEG1.public_keygen() c1, c2 = BobEG1.encrypt(orig_plaintext, AlicePub) plaintext = AliceEG1.decrypt(c1, c2) self.assertEqual(plaintext, orig_plaintext)
def lenstras_algorithm(n): # n is a composite number of two large primes, p and q ; n = p*q d = n i = 0 while d == n: A = random.randint(1,n-1) a = random.randint(1,n-1) b = random.randint(1, n-1) B = ((b*b)%n - (a*a*a)%n - A * a) % n E = curve(A, B, n) P = (a,b) #print("New Curve {"+str(i)+"}") for X in range(2, int(log2(n))): Q = E.multiply(P, X) # The internals of this will exit() the program and create a divisors of n file in the same directory this was launched P = Q if len(Q) == 3: # If we've found a divisor of n, could be n itself though d = Q[2] break i+=1 return d