Skip to main content

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 ecc module in your Python project.

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 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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_ecc-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file simple_ecc-0.1.0.tar.gz.

File metadata

  • Download URL: simple_ecc-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.6

File hashes

Hashes for simple_ecc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 42c6a251a56dcd832952eafc56bdf22968094ef6579b6827d8848d262f27c313
MD5 cc95ff5b0cc996cf0df65056a00ec038
BLAKE2b-256 f0356124c9cd5d2f430e29b6b51cea2a8839c4817816228bc7b64dfec826c0af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page