A simple elliptic curve cryptography library
Project description
simple-ecc
Overview
This project implements an Elliptic Curve Cryptography (ECC) library in Python. It provides functionalities to create elliptic curves, perform point addition and scalar multiplication on the curve, generate private and public keys, and calculate the entropy of keys.
Installation
To use this library, simply clone the repository and import the simple_ecc module in your Python project.
pip install simple-ecc
OR
git clone https://github.com/mohdluqman/simple-ecc.git
Usage
Creating an Elliptic Curve
To create an elliptic curve, initialize the EllipticCurve class with the required parameters.
from simple_ecc import EllipticCurve
a = 56698187605326110043627228396178346077120614539475214109386828188763884139993
b = 17577232497321838841075697789794520262950426058923084567046852300633325438902
p = 76884956397045344220809746629001649093037950200943055203735601445031516197751
Gx = 63243729749562333355292243550312970334778175571054726587095381623627144114786
Gy = 38218615093753523893122277964030810387585405539772602581557831887485717997975
n = 0xA9FB57DBA1EEA9BC3E660A909D838D718AFCED59
curve = EllipticCurve(a, b, p, Gx, Gy, n)
curve.print_curve()
Generating Keys
You can generate a private key and derive the corresponding public key using the following methods:
private_key = curve.generate_private_key()
public_key = curve.public_key_from_private(private_key)
print(f"Private Key: {private_key}")
print(f"Public Key: {public_key}")
Calculating Entropy
You can calculate the entropy of a private key using the following method:
from simple_ecc import KeyEntropyCalculator
entropy_calculator = KeyEntropyCalculator(curve)
entropy = entropy_calculator.calculate_entropy(private_key)
print(f"Entropy: {entropy}")
Generating Highest Entropy Key
You can generate the highest entropy private key and derive the corresponding public key as a point on elliptic curve using the following method:
best_private_key, best_entropy = entropy_calculator.generate_high_entropy_key(num_trials=100)
public_key = curve.public_key_from_private(best_private_key)
print(f"Best Private Key: {best_private_key}")
print(f"Highest Entropy: {best_entropy}")
print(f"Public Key: {public_key}")
print(f"Is Public Key Valid: {curve.is_point_on_curve(public_key)}")
Creating Elliptic Curve and Keys with Highest Entropy
You can create an elliptic curve and generate keys with highest entropy using the following method:
def create_elliptic_curve_and_keys(num_trials=1000):
a = 56698187605326110043627228396178346077120614539475214109386828188763884139993
b = 17577232497321838841075697789794520262950426058923084567046852300633325438902
p = 76884956397045344220809746629001649093037950200943055203735601445031516197751
Gx = 63243729749562333355292243550312970334778175571054726587095381623627144114786
Gy = 38218615093753523893122277964030810387585405539772602581557831887485717997975
n = 0xA9FB57DBA1EEA9BC3E660A909D838D718AFCED59
curve = EllipticCurve(a, b, p, Gx, Gy, n)
curve.print_curve()
entropy_calculator = KeyEntropyCalculator(curve)
best_private_key, best_entropy = entropy_calculator.generate_high_entropy_key(num_trials)
public_key = curve.public_key_from_private(best_private_key)
print(f"Best Private Key: {best_private_key}")
print(f"Highest Entropy: {best_entropy}")
print(f"Public Key: {public_key}")
print(f"Is Public Key Valid: {curve.is_point_on_curve(public_key)}")
return {
'curve': curve,
'best_private_key': best_private_key,
'public_key': public_key,
'best_entropy': best_entropy,
'is_public_key_valid': curve.is_point_on_curve(public_key)
}
result = create_elliptic_curve_and_keys(num_trials=1000)
License
This project is licensed under the MIT License. See the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple-ecc-0.1.1.tar.gz.
File metadata
- Download URL: simple-ecc-0.1.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
960b8bc9a4b5bf9091ceb376abe34080bb5552edb2f50c6cf2f0cb253517f2b7
|
|
| MD5 |
d8716ab4d4b11f84fd6e2de6ee9cc81b
|
|
| BLAKE2b-256 |
c9190911226c0343e970140dc583b6acbba0d59cdffa9f8a5dbe37991e0844c5
|
File details
Details for the file simple_ecc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: simple_ecc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66adf3d299c69814078560659b5075f14205da3321656d730d3e7211bc71b663
|
|
| MD5 |
e7be2fecc3af17f1d14c46c13cdb0fcd
|
|
| BLAKE2b-256 |
df66ff2d2c4be5143f4a0f08dbb1b577d0a2b33c2e8efc87137935ce30ccccc0
|