Alice and Bob information sharing code challenge
Diffie-Hellman coding challenge for secret information exchange using public/private keys
Background
Alice and Bob use the Diffie-Hellman key exchange algorithm to share secret information. Alice and Bob start with prime numbers, pick private keys, generate and share public keys, finally they then generate a shared secret key.
Your code module should take in two prime numbers, p and g and output the value of p and g, the private key a for Alice and b for Bob. Finally your program should print out the Shared Secret key for Alice and Bob.
If your implementation is correct, the Shared Secret keys should match.
Note: This challenge requires you to perform calculations on large numbers. Further information can be found at https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
Code requirements
- Ensure that your code is clean and uses good practice (e.g. error handling) and is commented well.
- Ensure that your code can work cross platform and across different versions of Python.
- Feel free to add as many bells and whistles as you so desired (e.g. Unit Tests)
Running the code
git clone https://github.com/Liam-Deacon/alice_and_bob
cd alice_and_bob
python3 -m alice_and_bob.key_share --help
CLI Example
$ python3 -m alice_and_bob.key_share -p 61 -g 53
Shared secret key: 60
It is also possible to specify the number of bits used for the generated private keys:
$ python3 -m alice_and_bob.key_share -p 88937 -g 104729 --bits=2048
Shared secret key: 39885
Python Example
>>> from alice_and_bob.key_share import main as code
>>> code(p=2, g=3) # only one possibility as primes very small
Shared secret key: 1
>>> code(61, 53)
Shared secret key: 34
>>> code(61, 53)
Shared secret key: 37
>>> code(61, 53)
Shared secret key: 9
>>> code(61, 53)
Shared secret key: 11
Release files for alice-and-bob 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| alice_and_bob-0.0.1.tar.gz | 270.6 kB | Details |
Release files / alice_and_bob-0.0.1.tar.gz
| Download URL | alice_and_bob-0.0.1.tar.gz |
|---|---|
| Size | 270.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8c6f4f7730d3c90e482d03d190969391d6b4b57fdbb4a1964e6c6b58d32e172
|
|
BLAKE2b-256 checksum How to use checksums |
e4b77982bb818c6533c62f663b272b0033cc4299385563bfdc13523fbd309d26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.10
|