Python Tutorials - Herong's Tutorial Examples - v2.21, by Herong Yang
Find Subgroup with Point Addition
This section provides a tutorial example on how to find the subgroup of a given point on an elliptic curve using a loop of point additions with tinyec Python library.
Once you have elliptic curve created with tinyec Python library, you can find the subgroup of a given point on the curve with a loop of point additions:
>>> import tinyec.ec as ec >>> s = ec.SubGroup(p=97,g=(0,0),n=1,h=1) >>> c = ec.Curve(a=2,b=3,field=s,name='p97a2b3') >>> p = ec.Point(curve=c,x=3,y=6) >>> print(p) (3, 6) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97) >>> z = ec.Inf(c) # represents the infinite point on the curve >>> r = p >>> for i in range(0,97): ... print(r) ... if (r == z): ... break ... r = r + p # point addition operation ... ^Z (3, 6) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97) (80, 10) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97) (80, 87) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97) (3, 91) on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97) Inf on "p97a2b3" => y^2 = x^3 + 2x + 3 (mod 97)
Ok. We found the subgroup of base point (or generator) of p = (3,6). The group order is 5.
Note that we created an ec.Inf object to represent the infinite point on the curve, and used it as the condition to stop the loop.
Table of Contents
Variables, Operations and Expressions
Function Statement and Function Call
List, Set and Dictionary Comprehensions
Packages and Package Directories
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Communicating with HTTPS Servers
►tinyec - Tiny Library for ECC
Perform Point Addition with tinyec
►Find Subgroup with Point Addition
Set Subgroup Order to Higher Value
Generating EC Public-Private Keys
Anaconda - Python Environment Manager