ECCHacks

A gentle introduction
to elliptic-curve cryptography

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

Clock addition

[Python snippets]

Clock addition is a standard way to add points on the clock. Examples:

  • "2:00" + "3:00" = "5:00". (5:00 is two hours after 3:00, and 3 hours after 2:00.)
  • "1:30" + "1:30" = "3:00".
  • "12:00" + "3:00" = "3:00".
  • "9:00" + "9:00" = "6:00".

The following Python function, returns the sum of two clock points P1 and P2:

     def clockadd(P1,P2):
       x1,y1 = P1
       x2,y2 = P2
       x3 = x1*y2+y1*x2
       y3 = y1*y2-x1*x2
       return x3,y3
     
     # example:
     P1 = (0.8,0.6)
     P2 = (0.28,0.96)
     
     print clockadd(P1,P2)
     # output: (0.936, 0.3519999999999999)
     print clockadd(P2,P1)
     # output: (0.936, 0.3519999999999999)
     # perfect real output would have been (0.936, 0.352)
     
     import math
     
     def oclock(time):
       radians = time * math.pi / 6
       return math.sin(radians),math.cos(radians)
     
     print clockadd(oclock(4),oclock(1))
     # output: (0.5000000000000002, -0.8660254037844385)
     print oclock(5)
     # output: (0.49999999999999994, -0.8660254037844387)
     # perfect real output would have matched

As before, these functions aren't perfectly accurate.

Something to try: Can you write a clocksub that subtracts two clock points? For example, subtracting "3:00" from "1:00" should give "10:00".


Version: This is version 2014.12.27 of the clockadd.html web page.