1
1
"""
2
2
© Yanni8 https://github.com/Yanni8
3
- This algorithmus is not efficient and also probaly not 100% secure.
3
+ This algorythmus is not efficient and also probaly not 100% secure.
4
4
Attackers could use Timing Attack (https://en.wikipedia.org/wiki/Timing_attack) to get informations about the private key
5
5
"""
6
6
7
- a = 0
8
- b = 7
9
- p = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1
10
- Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
11
- Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
12
- G = (Gx , Gy )
7
+ A = 0
8
+ B = 7
9
+ P = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1
10
+ GX = 55066263022277343669578718895168534326250603453777594175500187360389116729240
11
+ GY = 32670510020758816978083085130507043184471273380659243275938904335757337482424
12
+ G = (GX , GY )
13
13
14
14
def point_add (p1 : tuple , p2 : tuple ) -> tuple :
15
15
if p1 != p2 :
16
- lam = (p1 [1 ] - p2 [1 ]) * pow (p1 [0 ] - p2 [0 ], p - 2 , p )
17
- x3 = (pow (lam , 2 ) - p1 [0 ] - p2 [0 ]) % p
18
- y3 = (lam * (p1 [0 ] - x3 ) - p1 [1 ]) % p
16
+ lam = (p1 [1 ] - p2 [1 ]) * pow (p1 [0 ] - p2 [0 ], P - 2 , P )
17
+ x3 = (pow (lam , 2 ) - p1 [0 ] - p2 [0 ]) % P
18
+ y3 = (lam * (p1 [0 ] - x3 ) - p1 [1 ]) % P
19
19
return (x3 , y3 )
20
20
return point_dubl (p1 )
21
21
22
22
def point_dubl (p1 : tuple ) -> tuple :
23
- lam = (3 * p1 [0 ]** 2 + a ) * pow (2 * p1 [1 ], p - 2 , p )
24
- v = p1 [1 ] - lam * p1 [0 ] % p
25
- x3 = (lam ** 2 - 2 * p1 [0 ]) % p
26
- y3 = (lam * x3 + v ) * - 1 % p
23
+ lam = (3 * p1 [0 ]** 2 + A ) * pow (2 * p1 [1 ], P - 2 , P )
24
+ v = p1 [1 ] - lam * p1 [0 ] % P
25
+ x3 = (lam ** 2 - 2 * p1 [0 ]) % P
26
+ y3 = (lam * x3 + v ) * - 1 % P
27
27
return (x3 , y3 )
28
28
29
29
@@ -40,4 +40,3 @@ def calc_publ(private_key):
40
40
Q = point_dubl (Q )
41
41
binar = binar // 2
42
42
return publ
43
-
0 commit comments