Skip to main content

Elliptic Curve Cryptography and Genetic AES S-Box Optimizer

Project description

PyCastX is a Python package that provides:

  • Secure Elliptic Curve Cryptography (ECC) utilities
  • A Genetic Algorithm-based AES S-Box optimizer for enhanced cryptographic strength
  • High-entropy key generation using Shannon entropy

📦 Installation

Install directly from PyPI:

pip install pycastx

🔐 Features

🔸 Elliptic Curve Cryptography (ECC)

  • Define a custom elliptic curve over a finite field.
  • Generate secure private/public key pairs.
  • Validate whether a point lies on the curve.
  • Generate high-entropy keys based on Shannon entropy.

🔸 Genetic AES S-Box Optimizer

  • Generate substitution boxes (S-boxes) using Genetic Algorithms.

  • Optimize S-boxes for:

    • Non-linearity
    • Avalanche Effect
  • Useful in block cipher research and analysis.

🚀 Usage Examples

✅ ECC Key Generation

from pycastx.ecc import EllipticCurve, KeyEntropyCalculator

# Define custom curve parameters
a = 56698187605326110043627228396178346077120614539475214109386828188763884139993
b = 17577232497321838841075697789794520262950426058923084567046852300633325438902
p = 76884956397045344220809746629001649093037950200943055203735601445031516197751
Gx = 63243729749562333355292243550312970334778175571054726587095381623627144114786
Gy = 38218615093753523893122277964030810387585405539772602581557831887485717997975
n = 0xA9FB57DBA1EEA9BC3E660A909D838D718AFCED59

# Initialize curve
curve = EllipticCurve(a, b, p, Gx, Gy, n)

# Key entropy calculator
entropy_calc = KeyEntropyCalculator(curve)
private_key, entropy = entropy_calc.generate_high_entropy_key(num_trials=100)
public_key = curve.public_key_from_private(private_key)

print("Private Key:", private_key)
print("Entropy:", entropy)
print("Public Key:", public_key)
print("Is Public Key Valid?", curve.is_point_on_curve(public_key))

✅ AES S-Box Generation Using Genetic Algorithm

from pycastx.sbox import DynamicAESSBoxGA

# Initialize Genetic Algorithm
ga = DynamicAESSBoxGA(population_size=50, generations=10, mutation_rate=0.05)

# Generate optimized S-box
optimized_sbox = ga.apply_ga()

print("Optimized S-Box:")
print(optimized_sbox)

🧪 Running Tests

To run all tests using unittest:

python -m unittest discover tests

📚 API Reference

class EllipticCurve(a, b, p, Gx, Gy, n)

Represents an elliptic curve over a finite field.

Methods:

  • point_addition(P, Q)
  • scalar_multiplication(k, P)
  • generate_private_key()
  • public_key_from_private(private_key)
  • is_point_on_curve(P)

class KeyEntropyCalculator(curve)

Computes entropy and generates high-entropy ECC keys.

Methods:

  • shannon_entropy(data)
  • private_key_to_byte_array(private_key)
  • generate_high_entropy_key(num_trials=100)

class DynamicAESSBoxGA(population_size, generations, mutation_rate)

Optimizes AES S-boxes using a genetic algorithm.

Methods:

  • generate_sbox()
  • evaluate_sbox(sbox)
  • apply_ga()

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss.

🧠 Acknowledgements

This package was built to support research in:

  • Lightweight cryptography
  • ECC-based key generation
  • AES S-box design optimization

🔗 Links

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

pycastx-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycastx-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pycastx-0.1.1.tar.gz.

File metadata

  • Download URL: pycastx-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for pycastx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8bae6bc8a3d02e9c02b20e2ac844bdd6d030de5f7f4360b99a9d869a94544df3
MD5 e5b38a1af3044830ebb42c2f4b135119
BLAKE2b-256 08e0417bd7073681d40777034da0b3e950a15a75b2c622f6a03f9a759cdaceee

See more details on using hashes here.

File details

Details for the file pycastx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pycastx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for pycastx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e51fb6bb233d163d7c86774a32b54ad9a5624f39fc1ccb5b6e0080c63ed81379
MD5 f8a533e0405e3d19bdafa28ff560032b
BLAKE2b-256 dc634282823dbfc8008638c7e18dee55001fd9475850a584ee8dbbc201d2750b

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