Skip to content

Commit 8c5be91

Browse files
Make code and output a little bit more readable
1 parent a6301c5 commit 8c5be91

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bip-0340/reference.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def y(P):
3333
return P[1]
3434

3535
def point_add(P1, P2):
36-
if (P1 is None):
36+
if P1 is None:
3737
return P2
38-
if (P2 is None):
38+
if P2 is None:
3939
return P1
40-
if (x(P1) == x(P2) and y(P1) != y(P2)):
40+
if (x(P1) == x(P2)) and (y(P1) != y(P2)):
4141
return None
42-
if (P1 == P2):
42+
if P1 == P2:
4343
lam = (3 * x(P1) * x(P1) * pow(2 * y(P1), p - 2, p)) % p
4444
else:
4545
lam = ((y(P2) - y(P1)) * pow(x(P2) - x(P1), p - 2, p)) % p
@@ -49,7 +49,7 @@ def point_add(P1, P2):
4949
def point_mul(P, n):
5050
R = None
5151
for i in range(256):
52-
if ((n >> i) & 1):
52+
if (n >> i) & 1:
5353
R = point_add(R, P)
5454
P = point_add(P, P)
5555
return R
@@ -90,7 +90,7 @@ def is_square(x):
9090
return pow(x, (p - 1) // 2, p) == 1
9191

9292
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)))
9494

9595
def has_even_y(P):
9696
return y(P) % 2 == 0
@@ -144,7 +144,7 @@ def schnorr_verify(msg, pubkey, sig):
144144
return False
145145
e = int_from_bytes(tagged_hash("BIP340/challenge", sig[0:32] + pubkey + msg)) % n
146146
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):
148148
debug_print_vars()
149149
return False
150150
debug_print_vars()
@@ -168,7 +168,7 @@ def test_vectors():
168168
msg = bytes.fromhex(msg)
169169
sig = bytes.fromhex(sig)
170170
result = result == 'TRUE'
171-
print('\nTest vector #%-3i: ' % int(index))
171+
print('\nTest vector', ('#' + index).rjust(3, ' ') + ':')
172172
if seckey != '':
173173
seckey = bytes.fromhex(seckey)
174174
pubkey_actual = pubkey_gen(seckey)

0 commit comments

Comments
 (0)