Small, insecure and visual ECC library for educational purposes
Project description
minicurve
A very simple library developed by Marek Narozniak for visualizing finite field over elliptic curve. The idea of making this library originates in a cryptographyrelated tutorial series
 Elliptic Curve Cryptography and DiffieHellman Key Exchange
 Eliptic Curve Digital Signature Algorithm
 Schnorr Signature
 Pedersen Commitments and Confidential Transactions
Disclaimer. This library is NOT secure and NOT efficient. It is meant for purely educational purposes for visualizing tutorials. Do NOT use it for any cryptography applications!
Installation
Super simple!
pip install minicurve
Tutorial
Points addition is as simple as R=P+Q
, you can visualize parent points using arrows as follows.
from minicurve import MiniCurve as mc
from minicurve import Visualizer
# curve parameters
a = 1
b = 7
p = 13
P = mc(a, b, p, x=10, y=4, label='P', color='tab:orange')
Q = mc(a, b, p, x=9, y=11, label='Q', color='tab:orange')
# addition of curve points
R = P + Q
R.setColor('tab:red')
R.setLabel('R')
R.x_delta = 0.3
R.arrow_thickness = 0.01 # you can control the thickness of the arrow
R.arrow_head = 20 # and its head
# visualize the finite field
vis = Visualizer(a, b, p)
vis.makeField()
vis.points = [P, Q, R]
vis.generatePlot(title='points addition $P+Q=R$ using minicurve', addition=True)
# addition=True option will use arrows to visualize addition parents
vis.plot('images/example_add.png')
outputs
Multiplication by scalar works in similar way as you can simply P=4*G
and visualize the scalar using arrow path
from minicurve import MiniCurve as mc
from minicurve import Visualizer
# curve parameters
a = 0
b = 5
p = 7
G = mc(a, b, p, x=3, y=2, label='G', color='tab:green', tracing=True)
# tracing=True option will enabling plotting the arrows indicating scalar multiplication
# private key
k = 4
# public key
P = k*G
P.setColor('tab:orange')
P.setLabel('P')
P.x_delta = 0.08 # you can control the label placement relative to the point
# visualize the finite field
vis = Visualizer(a, b, p)
vis.makeField()
vis.points = [G, P]
vis.generatePlot(title='scalar multiplication $k \cdot G=P, k=4$ using minicurve')
vis.plot('images/example_mul.png')
outputs
FAQ
What are the valid values of colors?
We are using Matplotlib colors.
Thanks!
Code for computing quadratic residues from this gist. Thanks to Nakov.
Project details
Release history Release notifications  RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for minicurve0.0.1py3noneany.whl
Algorithm  Hash digest  

SHA256  9722e85a76de06e727939c190576d5ab451654e5c7819f108da9352e5fd62946 

MD5  0e078bf959c70483cb09464d64c962c3 

BLAKE2b256  bbaa5ab67737949af9e2967926c0c34cd2bb99d8bca4564f1c11f8c7b9139c04 