# ECCHacks

A gentle introduction
to elliptic-curve cryptography

 The clock: Real clock Clock addition
 Finiteness: Finite fields Finite clocks Clock crypto
 Elliptic curves: Edwards curves Edwards addition

## Finite clocks

As an alternative to the real clock one can use the integer clock: all pairs of integers (x,y) satisfying the equation x2+y2=1. The real clock has infinitely many points, while the integer clock has only four points: namely, (0,1), (1,0), (0,-1), and (-1,0); i.e., "12:00", "3:00", "6:00", and "9:00".

A larger example is the clock modulo 7. This clock consists of all pairs of integers modulo 7 satisfying this equation. The following Python script prints all points on the clock modulo 7:

```     for x in range(7):
for y in range(7):
if (x*x+y*y) % 7 == 1:
print (x,y)

# output: (0, 1)
# output: (0, 6)
# output: (1, 0)
# output: (2, 2)
# output: (2, 5)
# output: (5, 2)
# output: (5, 5)
# output: (6, 0)
```

We can use the original clockadd function to add points on this clock, after we've defined +,-,* for the field of integers modulo 7:

```     P1 = (F7(2),F7(5))
P2 = (F7(1),F7(0))
# output: (5, 5)
# output: (5, 5)
P3 = (F7(5),F7(5))
# output: (1, 0)
# output: (1, 0)
```

The above script to print all clock points becomes much slower if you replace 7 by a larger prime, but clock addition remains fast:

```     p = 1000003
Fp = F(1000003)
P = (Fp(1000),Fp(2))
print P2
# output: (4000, 7)
print P3
# output: (15000, 26)