Program structure#
| Class | Responsibility |
|---|---|
Main.java |
Application entry point, menu flow, mode selection, and final result display. |
Parameters.java |
Stores the public parameters \( q \) and \( \alpha \). |
KeyExchange.java |
Computes public keys and shared secret values. |
Encryptor.java |
Encrypts and decrypts messages using the shared secret. |
Validator.java |
Validates prime checks, parameter ranges, and message constraints. |
Helpers.java |
Handles input prompts and validation loops. |
Utils.java |
Provides support utilities such as random generation and formatting helpers. |
Design principle
The code follows separation of concerns, so each class has a focused role.
Workflow#
Input#
Collect \( q \) and \( \alpha \), typed in or generated automatically.
Keys#
Each participant selects a private key and computes a public key.
Exchange#
Public keys are exchanged and each side computes the shared secret.
Encryption#
A plaintext message of more than 20 characters is encrypted.
Decryption#
The ciphertext is decrypted to confirm correctness.
User modes#
| Mode | Purpose |
|---|---|
| Numerical example | Demonstrates the process with small educational values, either fixed (\( q = 23, \alpha = 5 \)) or auto-generated. |
| Live mode | Uses manual or auto-generated values for interactive testing. |
Example console interaction#
java Main
--- Royal Convoy - Secure Communication (Diffie-Hellman / ECDH Demo) ---
This program demonstrates how the control center and vehicles exchange keys securely.
MAIN MENU:
1) Numerical Example (Section 1.3 demo - fixed values)
2) Numerical Example (auto-generated values)
3) Live Mode (manual / auto parameters and private keys)
0) Exit
Choose an option: 3
...
Shared key = 7
Original Message = Please let this project work.
Encrypted Message = Jhs7D0vPYnq0...
Decrypted Message = Please let this project work.
Decryption OK = true