How did you get into Bitcoin?
__add__
method$F_{19}$
$11 + 6 = 17 \pmod{19}$
$17 - 6 = 11 \pmod{19}$
$18 + 14 = 3 \pmod{19}$
$4 - 12 = 11 \pmod{19}$
print((11 + 6) % 19) # 17
print((17 - 6) % 19) # 11
print((18 + 14) % 19) # 3
print((4 - 12) % 19) # 11
__add__
method
__sub__
method
$F_{19}$
$2 \times 4 = 8 \pmod{19}$
$7 \times 3 = 2 \pmod{19}$
$11^{3} = 1 \pmod{19}$
print(2 * 4 % 19) # 8
print(7 * 3 % 19) # 2
print(11 ** 3 % 19) # 1
print(pow(11, 3, 19)) # 1
__mul__
method
__pow__
method
Defined as the inverse of multiplication
$2 \times 4 = 8 \pmod{19} \implies \frac{8}{2} = 4 \pmod{19}$
$7 \times 3 = 2 \pmod{19} \implies \frac{2}{3} = 7 \pmod{19}$
$15 \times 4 = 3 \pmod{19} \implies \frac{3}{4} = 15 \pmod{19}$
$11 \times 11 = 7 \pmod{19} \implies \frac{7}{11} = 11 \pmod{19}$
$n^{p-1} = 1 \pmod{p}$ for all $n$ if $p$ is prime
This means we can do division:
$1/n = n^{-1} = n^{-1} \cdot 1 = n^{-1} \cdot n^{p-1} = n^{p-2} \pmod{p}$
or $1/n = n^{p-2} \pmod{p}$
$F_{19}$
$1/n = n^{p-2} \pmod{p}$
$2/3 = 2 \cdot 1/3 = 2 \cdot 3^{19-2} = 7 \pmod{19}$
$3/15 = 3 \cdot 1/15 = 3 \cdot 15^{19-2} = 4 \pmod{19}$
print(2 * 3**17 % 19) # 7
print(2 * pow(3, 17, 19) % 19) # 7
print(3 * 15**17 % 19) # 4
print(3 * pow(15, -1, 19) % 19) # 4
__truediv__
method
x, y = -1, -1
print(y**2 == x**3 + 5 * x + 7) # True
__init__
method to check that x and y are valid.
$y^2=x^3+ax+b$
$(x_1,y_1) = (x_1, y_1) + (\infty, \infty)$
$(x_1,y_1) + (x_1, -y_1) = (\infty, \infty)$
$(\infty, \infty)$ is zero in point addition
__init__
and __add__
methods to handle $(\infty, \infty)$. (use x=None, y=None
to represent the point)$y^2=x^3+ax+b$
$(x_3,y_3) = (x_1, y_1) + (x_2, y_2)$
$s = \frac{y_2-y_1}{x_2-x_1}$
$x_3 = s^2 - x_1 - x_2$
$y_3 = s(x_1-x_3) - y_1$
$y^2=x^3+5x+7$
What is $(2,5)+(3,7)$?
$s = \frac{y_2-y_1}{x_2-x_1} = (7-5)/(3-2) = 2$
$x_3 = s^2 - x_1 - x_2 = 4 - 2 - 3 = -1$
$y_3 = s(x_1-x_3) - y_1 = 2(2-(-1)) - 5 = 1$
$(2,5)+(3,7)=(-1,1)$
__add__
method to handle when $x_1 \neq x_2$$y^2=x^3+ax+b$
$(x_3,y_3) = (x_1, y_1) + (x_2, y_2)$
$s = \frac{3x_1^2+a}{2y_1}$
$x_3 = s^2 - 2x_1$
$y_3 = s(x_1-x_3) - y_1$
$y^2=x^3+5x+7$
What is $(2,5)+(2,5)$?
$s = \frac{3x_1^2+a}{2y_1} = (3 \cdot 2^2 + 5)/(2 \cdot 5) = 1.7$
$x_3 = s^2 - 2x_1 = 1.72 - 2 \cdot 2 = -1.11$
$y_3 = s(x_1-x_3) - y_1 = 1.7 \cdot (2+1.11) - 5 = 0.287$
$(2,5)+(2,5)=(-1.11,0.287)$
__add__
method to handle when $P_1 = P_2$