This project demonstrates the implementation of AES (Advanced Encryption Standard) encryption and decryption for secure communication between a client and a server. The project includes functionalities for encrypting and decrypting messages, benchmarking AES performance, and handling encrypted communication over a network.
- aes.py: Contains the core AES encryption and decryption functions.
- benchmark.py: Measures and plots the encryption and decryption times for different message sizes.
- client.py: Implements the client-side program to send encrypted messages to the server.
- server.py: Implements the server-side program to receive and decrypt messages from the client.
- Python 3.x
pycryptodomelibrary for AES encryptionmatplotliblibrary for plotting the performance benchmark
You can install the required dependencies using pip:
pip install pycryptodome matplotlib-
encrypt_message(message, secret_key): Encrypts a given plaintext message using AES in CBC mode. It returns the encrypted message, including the Initialization Vector (IV) concatenated with the ciphertext.
-
decrypt_message(encrypted_message, secret_key): Decrypts an encrypted message by extracting the IV and ciphertext, then using AES in CBC mode with the provided secret key to recover the original plaintext message.
- benchmark_aes_performance(): This function benchmarks the time taken for encryption and decryption for different message sizes (128, 256, 512, 1024, and 2048 bytes) and plots the results using
matplotlib. It shows how the time varies with message size.
-
client.py: The client program connects to the server, takes input from the user, encrypts the message using AES, and sends the encrypted message to the server.
-
server.py: The server listens for incoming encrypted messages from the client, decrypts them, and displays the decrypted message. After the communication ends, the server runs the AES performance benchmark.
-
Start the Server: Run
server.pyto start the server.python server.py
The server will listen for incoming connections on
127.0.0.1:5000. -
Start the Client: Run
client.pyto start the client.python client.py
The client will connect to the server and prompt you to enter a message. The message will be encrypted using AES and sent to the server.
-
Benchmarking: After the communication ends, the server will automatically run the performance benchmark, displaying the time taken for encryption and decryption for various message sizes.
Enter 'exit' to quit.
Enter message: Hello, server!
Encrypted message: b'...'
Server listening on 127.0.0.1:5000...
Connection established with ('127.0.0.1', 12345)
Encrypted message received: b'...'
Received message: Hello, server!
A plot showing the encryption and decryption times for different message sizes will be displayed after the server finishes processing.
Feel free to fork the repository and submit pull requests. If you find any bugs or have suggestions for improvements, please open an issue on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.
Sasanka - @zorodev
- 🌐 Portfolio: sasankawrites.in
- 📸 Instagram: @zorodev.exe
- 💻 GitHub: @ZoroDev0
Made with ❤️ by Zoro
⭐ Star this repository if you found it helpful!