@@ -33,13 +33,13 @@ def y(P):
33
33
return P [1 ]
34
34
35
35
def point_add (P1 , P2 ):
36
- if ( P1 is None ) :
36
+ if P1 is None :
37
37
return P2
38
- if ( P2 is None ) :
38
+ if P2 is None :
39
39
return P1
40
- if (x (P1 ) == x (P2 ) and y (P1 ) != y (P2 )):
40
+ if (x (P1 ) == x (P2 )) and ( y (P1 ) != y (P2 )):
41
41
return None
42
- if ( P1 == P2 ) :
42
+ if P1 == P2 :
43
43
lam = (3 * x (P1 ) * x (P1 ) * pow (2 * y (P1 ), p - 2 , p )) % p
44
44
else :
45
45
lam = ((y (P2 ) - y (P1 )) * pow (x (P2 ) - x (P1 ), p - 2 , p )) % p
@@ -49,7 +49,7 @@ def point_add(P1, P2):
49
49
def point_mul (P , n ):
50
50
R = None
51
51
for i in range (256 ):
52
- if (( n >> i ) & 1 ) :
52
+ if (n >> i ) & 1 :
53
53
R = point_add (R , P )
54
54
P = point_add (P , P )
55
55
return R
@@ -90,7 +90,7 @@ def is_square(x):
90
90
return pow (x , (p - 1 ) // 2 , p ) == 1
91
91
92
92
def has_square_y (P ):
93
- return not is_infinity (P ) and is_square (y (P ))
93
+ return ( not is_infinity (P )) and ( is_square (y (P ) ))
94
94
95
95
def has_even_y (P ):
96
96
return y (P ) % 2 == 0
@@ -144,7 +144,7 @@ def schnorr_verify(msg, pubkey, sig):
144
144
return False
145
145
e = int_from_bytes (tagged_hash ("BIP340/challenge" , sig [0 :32 ] + pubkey + msg )) % n
146
146
R = point_add (point_mul (G , s ), point_mul (P , n - e ))
147
- if R is None or not has_square_y (R ) or x (R ) != r :
147
+ if ( R is None ) or ( not has_square_y (R )) or ( x (R ) != r ) :
148
148
debug_print_vars ()
149
149
return False
150
150
debug_print_vars ()
@@ -168,7 +168,7 @@ def test_vectors():
168
168
msg = bytes .fromhex (msg )
169
169
sig = bytes .fromhex (sig )
170
170
result = result == 'TRUE'
171
- print ('\n Test vector #%-3i: ' % int ( index ))
171
+ print ('\n Test vector' , ( '#' + index ). rjust ( 3 , ' ' ) + ':' )
172
172
if seckey != '' :
173
173
seckey = bytes .fromhex (seckey )
174
174
pubkey_actual = pubkey_gen (seckey )
0 commit comments