Encrypted Chat Session Project (Python)
By: Amit Manbahal
Tags: Encryption, Encrypted Chat Session, Server, Client, Python

Our project was consisted of an implementation of a message server that encrypts the message that is being sent from the server to the client or vice versa. To start with, what is encryption? Encryption is defined as the method by which plaintext or any other type of data is translated from readable form to an encoded version that can be decoded by another entity. Further, a symmetric key is also known as a “secret key”. This in itself uses a single key that must be shared with any entity that intends to decrypt the encrypted data. We implemented in our project something known as Advanced Encryption Standard (AES) encryption. AES encryption is a symmetric block cipher that is implemented through software or hardware to encrypt sensitive data. There are three benefits to using encryption. Authentication, where the origin of the message can be verified. Integrity, proof that the contents of a message have not been changed. Lastly, nonrepudiation is the sender of the message cannot deny sending the message.

Moreover, the previous paragraph explains background on knowledge to know about our project we did. Going into detail about our project, we essentially divided the project into five phases. Phase 1 was consisted of studying python so we can write the code we needed for this project. Phase 2 we started coding and ensuring our server was able to talk with the client. Phase 3, (this was probably the hardest phase of this project) was where we started studying encryption more. We encrypted the message that we were sending back and forth between the client and the server. Phase 4, formatting the output so that the user sees on the screen so it’s easy to follow what is going on. Lastly, phase 5 was understanding that within our code there were some loopholes. However, with more time we can make the code better and also do a lot more than just an encrypted chat session between the server and the client. Studying python and the different types of encryptions was a key aspect in terms of having our project be a success. Once we took a week or two to fully understand everything it made things easier for us to start coding and getting a server and client talking with each other.

After we finished the base project, we started to ask ourselves, “How could this project be further improved and be used in the future?”. We came to the conclusion that having a more advanced knowledge of python was necessary for the various possibilities of adding extra code to the project that we do not know about currently. We also came to the conclusion that our code needed to be expanded to allow multiple users to access the server. At present, our project code only allows for one user to connect to the server at a time. We also believe that later on we could edit the code to also allow for a chat session that does not have to contain exactly sixteen characters. The possibility is also open for the user to input a username before entering the session is also being under consideration as a potential add on to our code to expand it.

Once the code has been streamlined and edited, it could have the potential to be a legit client-server based chatroom. All that would be necessary would be the P2P connection of knowing the exact IP address of the server. The server itself could possibly be made static where the I.P address does not need to change each time a connection is made to the clients.

Code for the Server

1.We imported built in libraries within Python

2.Hard coded the public key

3.Used AES encryption.

4.Created a local host (My computer) just for demonstration purposes but works with two different computers.

5.”socket.socket()” connects 2 nodes that are connected with each other

6.“socket.bind” links a socket to a network address

7.”socket.listen” listens to requests to connect to a particular address

8.“conn” accepts the connection

9.Now the program will display the connection with the client

10.Once the user on the client types a message it then shows the encrypted message and the decrypted message.

Code for the Client

1.We imported built in libraries within Python.

2.Hard coded the public key.

3.Used AES encryption.

4.Created a local host (My computer) just for demonstration purposes but works with two different computers.

5.”socket.socket()” connects 2 nodes that are connected with each other.

6.“socket.connect” connects to the server.

7.Now the program will prompt for user input.

8.“cipher.encrypt” encrypts the message that was inputted.

9.It then displays what the message has been encrypted to.

10.After it then sends the message to the server it connected to.