forked from qubd/mini_ecdsa
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests_mini_ecdsa.py
53 lines (42 loc) · 1.71 KB
/
tests_mini_ecdsa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#mini_ecdsa.py must to be in the same folder with this file.
from mini_ecdsa import *;
#tests the fucntions in mini_ecdsa.py
def run_test():
print("_____________________")
#smaller elliptic curve
C = CurveOverFp(0, 0, 7, 211);
P = Point(150, 22);
print("\n\n", "smaller curve:", C, ", generator point: ", P);
n = C.order(P)
print("n", n);
(d, Q) = generate_keypair(C, P, n); #limited value of d (max = n)
print("d", d, "Q", Q);
print("\ntest brute_force:");
crack_brute_force(C, P, n, Q, 150, 100);
print("\ntest BSGS:");
crack_baby_giant(C, P, n, Q);
print("\ntest pollard_rho:");
crack_rho(C, P, n, Q, 1);
(d1, Q1) = generate_keypair(C, P, n);
print("d1", d1, "Q1", Q1);
print("\ntest subtraction:", Q.__eq__(C.add(C.subtract(Q, Q1),Q1)));
print("\ntest divide:", Q.__eq__(C.mult(C.divide_point(Q, d1, n), d1)));
print("test get_Y (even Y):", C.getY(Q1.x, 0));
print("test get_point_by_X (odd Y):", C.get_point_by_X(Q1.x, 1));
print("test is on curve?:", C.contains(Point(Q1.x, C.getY(Q1.x,0))), C.contains(C.get_point_by_X(Q1.x,1)));
print("test is on curve (pow_mod)?:", C.contains(Point(Q1.x, C.getY(Q1.x,0))), C.contains(C.get_point_by_X(Q1.x,1)));
print("_____________________")
#end function
run_test(); #result of one test just as demo
"""
# test many random points with many iterations.
import time #to using interval
interval = 0.5; #seconds
# run tests
print ("Start : %s" % time.ctime())
for i in range(0, 100):
print ("continue : %s" % time.ctime())
time.sleep( interval ) # wait...
run_test(); # repeat test again, after some time
print ("End : %s" % time.ctime())
"""