Skip to main content

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 cryptography-related tutorial series

  1. Elliptic Curve Cryptography and Diffie-Hellman Key Exchange
  2. Eliptic Curve Digital Signature Algorithm
  3. Schnorr Signature
  4. 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

output-addition

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

output-multiplication

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.

Metadata

Release files for minicurve 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minicurve 0.1.0
File Size Uploaded
minicurve-0.1.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for minicurve 0.1.0
File Interpreter ABI Platform
minicurve-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / minicurve-0.1.0.tar.gz

Download URL minicurve-0.1.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f96565bf89fd639a82603869c28f5d85b763e66c3a1827e8198da3fbc2b92ee6
BLAKE2b-256 checksum
How to use checksums
f428570ab27b91f9769332b4d626cc3eef2a6e8d817e51cd61e5bd0f8d7110e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.4

Release files / minicurve-0.1.0-py3-none-any.whl

Download URL minicurve-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
187a651378e4d848a7506b258771680a7767c76fd34391443b9c4c826bd24279
BLAKE2b-256 checksum
How to use checksums
d759d024a533c032a412c0e60fc86b49f0b8b44afdaa415560c2386c86ffb1db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page