Public key cryptography involves three ``people'':
sage: load cong.sage # defines random_elliptic_curve command sage: E = random_elliptic_curve(next_prime(randrange(1000))) sage: print E Elliptic Curve defined by y^2 = x^3 + 508*x + 42 over Finite Field of size 577
sage: P = E.random_element() sage: P (386 : 331 : 1)Finally, Alice has to tell everybody the random elliptic curve and the random point in such a way that Bob can define it on his computer. In the above example, just report that the prime is , that the curve is EllipticCurve([36,3]), and the point is .
sage: b = randrange(1000); b 549
sage: b*P (472 : 340 : 1)
Announce to the world. But keep b secret.
sage: a = randrange(1000); a 779 sage: a*P (54 : 426 : 1)
sage: b*(a*P) (260 : 99 : 1) sage: a*(b*P) (260 : 99 : 1)
Q = P aP = E([54, 426]) for n in range(1,1000): if Q == aP: print n break else: Q = Q + PNOTE: There are better methods than the above simplistic brute force approach. But even the better methods aren't very good.
Once you have a shared secret, you can use it to encrypt a message in various ways, many very complicated. A very simple way is to simply add (modulo each digit of the shared secret key to the digits of your ``message'' (which we encode as a number).
William Stein 2006-07-07