No project description provided
Project description
HomegrownDHE
HomegrownDHE is a Python package that provides an implementation of the Diffie-Hellman key exchange algorithm. It is designed for educational purposes and demonstrates how two participants can securely exchange cryptographic keys over an insecure channel.
Installation
To install the package from PyPI, use the following command:
pip install homegrowndhe
Usage
The package provides a main script to demonstrate the Diffie-Hellman key exchange, as well as utility functions for testing and debugging.
Running the Main Script
To run the main script, simply execute the __main__.py
file:
python -m homegrowndhe
This will perform a Diffie-Hellman key exchange between two participants and print the results to the console.
Development Mode
To enable development mode, set the DEV_TEST
environment variable to True
. This will enable additional debug output and run the end-to-end tests:
export DEV_TEST=True
python -m homegrowndhe
Detailed Usage
Here is a detailed breakdown of the available functions and their usage:
main(test_iters=0) -> int
The main function to demonstrate the Diffie-Hellman key exchange between two participants.
test_iters
: Number of test iterations to run. Defaults toTEST_ITERATIONS
.- Returns an integer exit code. A non-zero exit code indicates an error.
test_end_to_end(iterations=1)
Function to perform end-to-end tests of the Diffie-Hellman key exchange.
iterations
: Number of test iterations to run. Defaults to 1.
Utility Functions
The package includes several utility functions for terminal output and numeric operations:
twidth()
: Returns the terminal width.cprint(*args, padding=3, **kwargs)
: Centered print with padding.blockprint(txt)
: Block print with centered text.p_print(*args, **kwargs)
: Pretty print for development mode.get_digits(s: str) -> str
: Extracts digits from a string.is_long_num(_s: str, min_d: int = 100) -> bool
: Checks if a string contains a long numeric value.get_long_numerics(s: str, min_d: int = 100) -> List[str]
: Extracts long numeric values from a string.
Diffie-Hellman Key Exchange Classes
DiffieHellmanParticipant
A class representing a participant in the Diffie-Hellman key exchange.
__init__(self, parameters: DSA.DsaKey)
: Initializes a participant with given DSA parameters.compute_shared_key(self, other_public_key: int) -> int
: Computes the shared key using the other participant's public key.
generate_large_prime_parameters(bits: int = 2048) -> DSA.DsaKey
Generates large prime parameters for the Diffie-Hellman key exchange.
bits
: The number of bits for the prime number. Defaults to 2048.
Testing
To run the tests, use the following command:
pytest
This will execute the tests defined in the test_homegrowndhe.py
file.
License
This project is licensed under the MIT License.
Feel free to modify the README to suit your specific needs or add more sections if necessary.
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
File details
Details for the file homegrowndhe-0.3.3.tar.gz
.
File metadata
- Download URL: homegrowndhe-0.3.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5bae9f0926d35109cf35adf086661b9ea516d855ae44ab1f4d19ff3fe242810 |
|
MD5 | 939621aa31a235ac72eb82fbd05ec10e |
|
BLAKE2b-256 | e834e8a072d6d0c484f42e54fd1fecdf5f1438ab026e8e3c0403d1c311297823 |
File details
Details for the file homegrowndhe-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: homegrowndhe-0.3.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b0c21a5b83f90a105fc82badba5e16e8043290fb72b7a299397d3cb3ff690a |
|
MD5 | e3f5f7f937b29810570caad4416d2241 |
|
BLAKE2b-256 | 89f64210a1e6ed948e483685ecd9c3d20b667f8d8edb4473be6c6fe36bac828c |