Python Program for Integer Elliptic Curves

This section provides simple Python program, IntegerEllipticCurve.py, that searches integer points on any given elliptic curve with integer coefficients.

If you are interested to find the element set of elliptic curve points in 2-dimensional integer space, here is my simple Python program, IntegerEllipticCurve.py, that searches integer points on any given elliptic curve with integer coefficients:

```# IntegerEllipticCurve.py
#
import sys

if (len(sys.argv) < 3):
print("Usage: python IntegerEllipticCurve.py a b")
exit()

aa = sys.argv
bb = sys.argv
a = int(aa)
b = int(bb)

r = 4*a**3 + 27*b**2
if (r == 0):
print("Error: (a, b) = ("+aa+", "+bb+") and 4a^3 + 27b^2 == 0")
exit()

print("Elliptic equation: y^2 = x^3 + ax + b with (a, b) = ("
+aa+", "+bb+")")

# Find a x such that x^3 + ax + b < 0
x = 0
r = x**3 + a*x + b
while (r >= 0):
x = x - 1
r = x**3 + a*x + b
print("Starting with: x = "+str(x))

# Find a x such that x^3 + ax + b >= 0
while ( r<0 ):
x = x + 1
r = x**3 + a*x + b
print("First condidate: x = "+str(x))

# Check every x < 100000
y = 0
while (x < 100000):
r = x**3 + a*x + b
l = y**2

while (l < r):
y = y + 1
l = y**2

# print("(x, y) = ("+str(x)+", "+str(y)+")")
# print("(r, l) = ("+str(r)+", "+str(l)+")")
if (l == r):
print("Point on curve: (x, y) = ("+str(x)+", "+str(y)+")")

x = x + 1

print("Ended with (x, y, r, l) = "
+str(x)+", "+str(y)+", "+str(r)+", "+str(l)+")")
exit()
```

If you run it with (a,b) = (1,4), you will get:

```C:\herong> python IntegerEllipticCurve 1 4

Elliptic equation: y^2 = x^3 + ax + b with (a, b) = (1, 4)
Starting with: x = -2
First condidate: x = -1
Point on curve: (x, y) = (0, 2)
Point on curve: (x, y) = (0, -2)
Point on curve: (x, y) = (4128, 265222)
Point on curve: (x, y) = (4128, -265222)
Ended with (x, y, r, l)
= 100000, 31622303, 999970000400002, 999970047023809)
```

The program works and found 4 points in the range of (x,y) < (1000000, 31622303):

```(x, y) = (0, 2)
(x, y) = (0, -2)
(x, y) = (4128, 265222)
(x, y) = (4128, -265222)
```

Of course, you can increase the search range to a higher number. But the program may crash with integer overflow exceptions or run for a long long time.