To install the dependencies, run the following commands:
pip install pycryptodome
pip install socket
pip install tqdm
pip install matplotlib
To use the program, split the terminal and run the server and client chatters in separate terminals
To run the Server use the command:
python server.py
To run the Client use the command:
python client.py
Please make sure to run the server first and then the client
To close the chat simply type
exit
That's it! you can start chatting now and all your conversations are secured with RSA 🔒
The Transmorpher
class is responsible for encoding and decoding messages.
This is the core class where RSA encryption and decryption is implemented. The class constructor takes the key size in bits and a class for encoding/decoding (Transmorpher
). Dependency injection is used so that the RSA class doesn't depend on how the encoding/decoding is done, and different schemes can be used without any changes to the RSA class. The class includes the following public methods:
generate_keys()
encrypt()
decrypt()
The Chatter
class is a virtual class responsible for handling the sockets and threading. It has two main methods:
connect()
chat()
The two classes ClientChatter
and ServerChatter
inherit from this class and implement the virtual function connect()
.
The ClientChatter
and ServerChatter
classes are defined here. In the main function, an object of each chatter is created and used for chatting.
The code for breaking RSA is implemented in this notebook, In addition, the analysis results and conclusions are shown at the end.