Coding Encrypted Chat in Python

NeuralNine
11 Nov 202220:32

Summary

TLDRIn this tutorial video, the host guides viewers through the process of creating an encrypted chat application in Python. Utilizing the RSA library for encryption and core Python modules like socket and threading, the video demonstrates how to establish a secure communication channel that prevents eavesdropping on network traffic. The host also illustrates the effectiveness of encryption using Wireshark to compare clear text and encrypted message transmission, emphasizing the importance of keeping private keys secure for maintaining message confidentiality.

Takeaways

  • ๐Ÿ˜€ The video is a tutorial on creating an encrypted chat in Python.
  • ๐Ÿ”’ It emphasizes the importance of encryption for secure communication, preventing third-party eavesdropping.
  • ๐Ÿ“š The tutorial uses the RSA library for encryption, which is an external module in addition to Python's core modules like socket and threading.
  • ๐Ÿ”‘ The concept of asymmetric encryption is introduced, explaining the use of a public key for encryption and a private key for decryption.
  • ๐Ÿ”„ The video demonstrates creating a public-private key pair at the start of the session, which is not typical for long-term use cases.
  • ๐Ÿ’ผ The public key can be shared openly, while the private key must remain confidential to ensure message security.
  • ๐Ÿ”— The script involves a client-server model with a choice for the user to either host or connect to a chat session.
  • ๐Ÿค– The script uses threading to handle both sending and receiving messages simultaneously in separate threads.
  • ๐Ÿ“ก The tutorial includes a practical demonstration of network traffic using Wireshark to contrast encrypted versus unencrypted messages.
  • ๐Ÿ›‘ The video shows that without encryption, messages can be easily read by sniffing network traffic, but with encryption, the content is secure.
  • ๐ŸŽ“ The tutorial concludes with a demonstration of the encrypted chat in action and a comparison using Wireshark, highlighting the security benefits of encryption.

Q & A

  • What is the main topic of the video?

    -The video is about building an encrypted chat application in Python.

  • Why is encryption important in chat applications?

    -Encryption is important to ensure that the communication between clients is secure and cannot be easily intercepted or read by third parties.

  • What is the difference between encrypted and unencrypted network communication?

    -Encrypted communication means that the messages are encoded and can only be decoded by the intended recipient using a private key, making it secure against eavesdropping. Unencrypted communication sends messages in clear text, which can be easily read by anyone who can access the network traffic.

  • What tool is used in the video to demonstrate the difference between encrypted and unencrypted network traffic?

    -Wireshark is used to capture and analyze network traffic to show the difference between encrypted and unencrypted messages.

  • What is the RSA library used for in this context?

    -The RSA library is used for implementing asymmetric encryption, which involves a public key for encrypting messages and a private key for decrypting them.

  • How does asymmetric encryption with RSA work?

    -In asymmetric encryption, there are two keys: a public key that can be shared with anyone and is used to encrypt messages, and a private key that is kept secret and is used to decrypt messages. The private key can only decrypt messages that were encrypted with the corresponding public key.

  • What are the two main functions that handle message sending and receiving in the chat application?

    -The two main functions are the sending messages function and the receiving messages function, both of which run in separate threads to handle communication with the client.

  • How are the keys exchanged between clients in the encrypted chat application?

    -The keys are exchanged by sending the public key of one client to the other client over the established connection. The public key is then used to encrypt messages that can only be decrypted with the recipient's private key.

  • What is the significance of using a private key and a public key in the encryption process?

    -The private key is used to decrypt messages that were encrypted with the corresponding public key. It is kept secret to ensure that only the intended recipient can decrypt and read the messages. The public key can be shared openly and is used to encrypt messages for the recipient.

  • How does the video demonstrate the effectiveness of the encryption in the chat application?

    -The video demonstrates the effectiveness of encryption by showing the inability to read the content of encrypted messages when using Wireshark to sniff network traffic, as opposed to the clear text messages that can be easily read when encryption is not used.

Outlines

00:00

๐Ÿ”’ Building an Encrypted Chat in Python

The video introduces a tutorial on creating an encrypted chat application in Python. The host explains the concept of encrypted communication where messages are encrypted at the sender's end and decrypted at the receiver's, preventing unauthorized access to the message content. The demonstration includes using the RSA library for encryption and decryption, and the core Python modules like 'socket' and 'threading' for handling connections. The host also plans to compare encrypted and unencrypted network traffic using Wireshark.

05:00

๐Ÿค– Setting Up the Chat Environment

This paragraph details the initial setup for the chat application, including the creation of a server socket and binding it to a local IP address and port. The script differentiates between hosting a chat and connecting to an existing one, with the user's choice determining the role of the client. The server is set to accept only one connection, and placeholders are used for client communication. The paragraph also outlines the structure for sending and receiving messages in a loop, with threading introduced for asynchronous communication.

10:01

๐Ÿ”„ Exchanging Keys for Asymmetric Encryption

The host discusses the process of exchanging public keys between clients to enable encrypted communication. Each client generates a public-private key pair using the RSA library, with the public key being shared openly while the private key remains secret. The video script includes code snippets for sending the public key in PEM format and receiving it from the partner client. The paragraph also addresses the need for both clients to send and receive public keys to establish a secure communication channel.

15:05

๐Ÿ“น Demonstrating Encryption with Wireshark

After establishing the basic chat functionality, the host proceeds to implement RSA encryption for messages. The script is modified to encrypt messages before sending and decrypt them upon receipt. The host then uses Wireshark to demonstrate the difference between encrypted and unencrypted network traffic. By sniffing the network, the host shows how clear text messages can be easily read without encryption, emphasizing the importance of encryption for secure communication.

20:05

๐Ÿ”’ Finalizing the Encrypted Chat Application

The final part of the script involves running the chat application with encryption enabled and using Wireshark to confirm that the messages are no longer readable as clear text. The host tests the application by sending messages and observing that the encrypted data packets are uniform in size and their content is inaccessible. The video concludes with the host sending a long message to test the system's response and confirming that the encrypted chat application successfully prevents eavesdropping.

๐Ÿ“ข Wrapping Up and Inviting Engagement

In the concluding paragraph, the host wraps up the tutorial by summarizing the process of building an encrypted chat in Python and encourages viewers to like, comment, and subscribe for more content. The host also reminds viewers to hit the notification bell to stay updated with future videos, ending the tutorial on a friendly and engaging note.

Mindmap

Keywords

๐Ÿ’กEncrypted Chat

An encrypted chat refers to a communication system where messages are encoded or scrambled to ensure that only the intended recipient can read them. In the video's context, the theme revolves around building such a system in Python, where messages are encrypted before being sent and decrypted upon receipt, preventing unauthorized third parties from understanding the content of the messages.

๐Ÿ’กPython

Python is a high-level, interpreted programming language known for its readability and efficiency. In the video, Python is the chosen language for developing an encrypted chat application. The script demonstrates how to use Python's socket module, threading module, and an external RSA library to create a secure chat system.

๐Ÿ’กRSA

RSA is an asymmetric cryptographic algorithm used for secure data transmission. In the video, the RSA library is utilized for encryption and decryption purposes in the chat application. It involves using a pair of keys, where one is public and can be shared with anyone to encrypt messages, and the other is private, kept secret by the owner to decrypt them.

๐Ÿ’กAsymmetric Encryption

Asymmetric encryption is a cryptographic system that uses two different keys: a public key for encryption and a private key for decryption. The video explains that in this system, the public key can be known by everyone and is used to encrypt messages that only the private key holder can decrypt, ensuring the security of the communication.

๐Ÿ’กSocket Module

The socket module in Python provides a low-level networking interface, allowing the creation of communication channels between different machines. In the video, the socket module is used to establish TCP connections for the encrypted chat, enabling the exchange of messages between clients.

๐Ÿ’กThreading Module

The threading module in Python facilitates the creation of threads, which are lightweight processes that can run concurrently. In the context of the video, threading is used to handle simultaneous tasks such as sending and receiving messages in the chat application without blocking the main execution flow.

๐Ÿ’กWireshark

Wireshark is a network protocol analyzer used for monitoring and inspecting network traffic. In the video, Wireshark is demonstrated to illustrate the difference between encrypted and unencrypted network traffic. It is used to show that encrypted messages appear as random bytes, protecting the content from being easily read by unauthorized parties.

๐Ÿ’กPublic and Private Key

In the context of asymmetric encryption, a public key is openly shared and used to encrypt messages, while a private key is kept secret and used to decrypt them. The video explains that in the chat application, each user has a public-private key pair, and they exchange public keys to enable secure communication.

๐Ÿ’กTCP Chat

TCP, or Transmission Control Protocol, is a connection-oriented protocol used for reliable network communication. The video mentions building a TCP chat, which means the chat application uses TCP to ensure that messages are delivered successfully between clients before they are encrypted and decrypted.

๐Ÿ’กNetwork Traffic

Network traffic refers to the exchange of data packets across a computer network. In the video, the term is used to describe the data being sent over the network between chat clients. The video demonstrates how encryption affects the visibility of this traffic, making it unreadable to eavesdroppers when encrypted.

Highlights

Introduction to building an encrypted chat in Python using RSA library for encryption.

Explanation of the importance of encryption in secure communication to prevent eavesdropping.

Demonstration of the difference between encrypted and unencrypted network traffic using Wireshark.

Overview of asymmetric encryption with public and private keys in RSA.

Instructions on installing the RSA library using pip.

Code walkthrough for setting up a basic TCP chat server and client in Python.

Description of the process for clients to choose to host or connect to a chat session.

Explanation of the socket binding process to an IP address and port for the server.

Discussion on the exchange of public keys between clients for mutual encryption.

Implementation of threading for concurrent sending and receiving of messages.

Debugging a script to ensure proper thread execution for chat functionality.

Introduction of RSA encryption for message exchange in the chat application.

Generation of public-private key pairs at the start of the chat session.

Transmission of public keys between clients for encryption purposes.

Encryption of messages using the partner's public key before sending.

Decryption of received messages using the client's private key.

Testing the encrypted chat application and observing the clear text difference.

Using Wireshark to demonstrate the inability to read encrypted messages.

Conclusion on the effectiveness of the encrypted chat and its security implications.

Call to action for viewers to like, comment, subscribe, and turn on notifications for future videos.

Transcripts

play00:00

what is going on guys welcome back in

play00:02

today's video we're going to learn how

play00:03

to build an encrypted chat in Python so

play00:05

let us get right into it

play00:10

[Music]

play00:15

alright so I already have quite a lot of

play00:17

tutorials on this channel on how to

play00:19

build a chat in Python beat a TCP chat a

play00:22

UDP chat a TCP chat room a web chat and

play00:25

flask and in today's video we're going

play00:27

to build an encrypted chat which means

play00:29

that the communication between the

play00:30

individual clients is going to be

play00:32

encrypted we will not send any clear

play00:33

text messages we will encrypt the

play00:36

messages at the sending client and they

play00:37

will be decrypted at the receiving

play00:39

client making it basically impossible

play00:42

for me as a third party to just listen

play00:44

to the network traffic and say hey this

play00:46

is the content of the message I can read

play00:48

it as well just because I'm listening to

play00:50

the network connection I can see what

play00:51

you guys are talking about this is not

play00:53

possible when the connection is

play00:54

encrypted and in fact I'm going to show

play00:56

you the difference between uh encryption

play00:59

and not not encryption by using

play01:02

Wireshark and actually listening to the

play01:04

network traffic in this case only on my

play01:06

machine but this can also be done in a

play01:07

network if you're a router or something

play01:09

you can just listen to the network

play01:10

traffic that's happening and you can see

play01:12

okay what package is being sent you can

play01:14

extract the messages in cleared text

play01:16

unless they are encrypted so this is

play01:19

what we're going to do today in Python

play01:21

and for that we're going to use One

play01:22

external Library called RSA this is

play01:24

going to be the library that we use for

play01:25

the encryption and the rest is going to

play01:28

be done in core python so we're going to

play01:29

use the socket module the threading

play01:31

module for the connection and everything

play01:33

and we're going to use RSA the external

play01:35

module for the actual encryption and for

play01:38

that we're going to open up the command

play01:39

line and we're going to say pip install

play01:42

RSA and this is asymmetric encryption so

play01:45

this basically means in a nutshell we

play01:47

have a private key and a public key and

play01:50

the public key is known by everyone so

play01:52

if I have a public key you can know it

play01:54

everyone can know it there's no secret

play01:56

about this key everyone can know this

play01:58

key and everyone can use this key to

play02:00

encrypt a message for me and this

play02:02

encrypted message can only be decrypted

play02:05

with my private key which hopefully only

play02:08

I know so the private key is also

play02:10

sometimes called the secret key should

play02:12

be kept secret at all times so only I

play02:15

can know it because that's the only way

play02:16

to decrypt the message and it's is

play02:18

called asymmetric because we use a

play02:20

different key for the encryption in a

play02:22

different key for the decryption it's

play02:24

not like using a password that you just

play02:25

you know use to encrypt and decrypt

play02:27

something you use a public key that is

play02:29

known by everyone everyone can use that

play02:31

to encrypt a message specifically for

play02:33

you and only you can decrypt that

play02:35

message with the respective private key

play02:37

and it's basically impossible to derive

play02:41

the private key from the public key so

play02:42

that's the basic idea here and this is

play02:44

what we're going to use as an encryption

play02:46

here and we're going to start by saying

play02:48

import socket

play02:50

we're going to also import threading

play02:54

and we're going to say import RSA and

play02:57

before we talk about anything regarding

play02:59

the

play03:00

um encryption we're going to have a

play03:02

basic choice because we want to use one

play03:04

script in this video for the client and

play03:06

we don't want to use a service script

play03:08

and a client script so we want one

play03:10

Central script and you can choose

play03:12

whether you want to host or you want to

play03:14

connect because one client will have to

play03:16

host a conversation and one client will

play03:19

connect to the uh to the hosted socket

play03:22

because you cannot just have two clients

play03:24

talking to each other one client has to

play03:25

also

play03:27

um host a connection at least when we

play03:29

use TCP in UDP we could just send

play03:31

packages so for that reason we're going

play03:34

to say Choice equals input do you want

play03:37

to host this is option one or do you or

play03:43

let's say or to

play03:45

connect option two

play03:48

and then we say if maybe not a question

play03:50

mark maybe colon

play03:54

if the choice is equal to one then we're

play03:58

going to host the connection so we're

play03:59

going to say server equals socket dot

play04:03

socket socket Dot afinet and socket dot

play04:06

stockstream that basically means

play04:08

internet socket TCP because connection

play04:10

oriented protocol here if you want to

play04:13

use UDP you would just say sock dgram

play04:15

for datagram and then we say server dot

play04:19

bind and we bind it to the local ipv4

play04:22

address which can be found out in the

play04:24

terminal on Windows by saying ipconfig

play04:27

so in the command line

play04:29

um we just go to the ethernet adapter

play04:32

and we go to ipv4 and we copy this IP

play04:35

address here

play04:37

and I'm bind it to the Tuple of this and

play04:39

the port number 99999

play04:43

that's the basic idea and now we say

play04:45

server Dot listen

play04:48

and this is going to be a client that

play04:51

will only accept one connection so we

play04:53

don't need anything to handle uh we

play04:56

don't we don't need

play04:58

um multiple connections which is why

play05:00

we're going to call the accept function

play05:01

only once and we're going to say that

play05:03

the client and the address that is

play05:05

connected actually we don't need the

play05:07

address so we can just leave this as an

play05:08

empty as a placeholder here as an

play05:12

unnamed return value so client is going

play05:14

to be equal to server dot accept so when

play05:18

a client connects to that server it's

play05:20

going to just accept and this client

play05:22

here will be our communication method to

play05:25

that client that connected

play05:28

um that's the idea here and then what

play05:30

we're going to do

play05:32

uh or actually let's do that later on um

play05:35

we're going to exchange the keys here

play05:36

because the other client needs to know

play05:38

our public key and we need to know the

play05:40

public key of the other client so that

play05:42

they can encrypt something for us and we

play05:44

can encrypt something for them uh but

play05:46

we're going to add this here in a second

play05:47

so let's just accept the connection for

play05:49

now and let's say also otherwise we're

play05:51

actually elif the choice happens to be

play05:55

two then we're going to say that the

play05:57

client is equal to socket socket again

play06:00

socket

play06:02

AF inet sock stream

play06:05

but this time we're going to connect

play06:08

client dot connect to in this case we're

play06:11

going to use the same IP address of

play06:13

course if you use this across the

play06:15

network or maybe even in the internet

play06:17

you would want to specify your IP

play06:19

address here and the other person would

play06:21

specify

play06:22

um

play06:23

the IP address of you your public IP

play06:27

address

play06:27

and you would specify if you connect the

play06:30

public IP address of the other person

play06:32

but in this case all of this happens on

play06:34

one machine so we're going to do it with

play06:37

the same IP address of course you can

play06:38

also ask for input so you can say IP

play06:40

equals input enter the IP address if you

play06:43

want to but in this case I'm going to

play06:44

use only my IP address so that's not

play06:46

necessary

play06:48

um and then here we would also exchange

play06:51

the key otherwise we're going to say

play06:53

exit

play06:54

because that's an invalid input and then

play06:58

essentially all we need to do is we need

play06:59

to send messages and receive messages so

play07:01

we're going to have uh one function

play07:03

that's going to run a separate thread

play07:06

which is going to be the sending

play07:07

messages function

play07:10

is going to run with a parameter C which

play07:12

is going to be our client and we're

play07:14

going to say while true we're going to

play07:16

be asked for new messages so message is

play07:18

going to be inputs what do you want to

play07:21

send to this person and then we're going

play07:22

to just say C sent

play07:26

message dot encode

play07:29

and uh we're gonna print you and then

play07:33

whatever you

play07:34

sent to the other client

play07:37

so that you have a protocol a log

play07:40

um and then

play07:42

we're going to also have a receiving

play07:46

messages

play07:49

function which is going to say while

play07:51

true

play07:52

just print partner whatever the partner

play07:55

says and this is going to be C receive

play07:58

1024 bytes decode

play08:03

that is the idea and then we're going to

play08:05

just say threading dot threat

play08:09

we don't need the input here

play08:11

threading.thread one is going to Target

play08:13

the sending messages function

play08:17

um we're going to pass as arguments here

play08:19

the client

play08:21

and one is going to be the receiving

play08:24

messages also with the argument client

play08:27

uh what's the problem here client can be

play08:30

undefined okay we're not gonna care

play08:32

about this year because it's not going

play08:33

to be undefined uh and one nice thing

play08:36

you can see here is the decline is

play08:37

always going to be the correct object to

play08:39

talk about because we don't need the

play08:40

server the server is only made for

play08:41

accepting the connection the client is

play08:44

the accepted connection so this is the

play08:45

client we use to communicate with the

play08:47

other client and here we also have the

play08:49

client that we use to communicate so

play08:50

basically after going through this block

play08:52

here the client is going to be declined

play08:54

and we can just do it like that so this

play08:57

should already be an unencrypted chat

play08:59

so I should already be able to run a

play09:02

terminal here

play09:03

and what was the key bind for split I

play09:06

hope this is it there you go

play09:09

I'm gonna navigate to my current working

play09:12

directory which is this one and I'm

play09:16

gonna do this here as well

play09:20

uh wrong directory

play09:27

and

play09:29

now we're going to run main.py here

play09:32

we're going to run main.py here

play09:36

and I'm going to say I want to host and

play09:38

I'm going to say I want to connect

play09:41

and this crash the script why is that oh

play09:45

because we need to start the threads as

play09:49

well

play09:51

that is the issue

play09:55

so let's do the same thing I want to

play09:57

host I want to connect

play09:59

hey

play10:01

hey hello

play10:03

what's up

play10:06

not much there you go so this works

play10:11

um this is the ordinary connection now

play10:13

we're going to encrypt this connection

play10:14

so we're going to use RSA first of all

play10:17

when we start the script to create our

play10:19

own public private uh key pair and

play10:22

usually you don't generate public and

play10:24

private key for every session you have

play10:26

your public key for a certain amount of

play10:28

time and you just put it on your website

play10:30

or something

play10:31

um on a public website and uh you don't

play10:34

necessarily generate it for each session

play10:36

but in this case we're going to do it

play10:38

like that we're going to say that the

play10:40

public

play10:42

key

play10:43

private key

play10:46

is going to be equal to RSA new keys

play10:49

1024 bytes

play10:51

or bits not sure

play10:53

um and then we say

play10:56

also that the public key of the partner

play10:58

is going to be none by default

play11:02

and we're going to get it then via the

play11:04

socket connection so in this case here

play11:06

once we accepted the connection we're

play11:08

going to start by saying client dot send

play11:11

so the hosting person the hosting client

play11:14

is going to send the key first we're

play11:16

going to send to our other client the

play11:19

public key but of course in order to be

play11:21

able to send it we need to package it as

play11:23

bytes so we're going to say public key

play11:25

dot safe pkcs1

play11:30

um

play11:31

and this is going to be sent

play11:35

um

play11:38

wasn't like yeah we need to specify the

play11:40

format which is pem so basically we take

play11:42

the public key we save it in this format

play11:44

pm and then we receive also the public

play11:47

key of the other client by saying public

play11:53

well the partner is going to be equal to

play11:55

client receive

play11:57

1024 bytes and this is going to be the

play12:01

basis for the public key and we're going

play12:03

to say RSA public key uh what was it RSA

play12:08

uh public key.load pkcs1

play12:13

whatever we get here

play12:15

and this is how it works we're going to

play12:17

do the same thing down here but we're

play12:19

going to do it the other way around

play12:20

because when one client is sending the

play12:22

other has to receive so the hosting

play12:25

client will send first and then receive

play12:26

and the connecting client will receive

play12:28

and then send

play12:30

and then the only thing that we need to

play12:31

change now that we have that is we need

play12:33

to encrypt every message and we need to

play12:35

decrypt every message so instead of just

play12:37

sending we're going to say

play12:40

um RSA dot encrypt

play12:43

we're going to encrypt the message dot

play12:45

encode

play12:45

so the encoded message will be encrypted

play12:48

with the public key of the partner so

play12:51

that the partner can then decrypt it

play12:53

with the private key and we're now the

play12:56

partner the partner or where now we

play12:59

we're receiving from the partner in this

play13:01

case we're not just printing whatever we

play13:02

get here we're going to say that

play13:05

um

play13:07

what we want to print is RSA dot decrypt

play13:11

and this is going to be whatever we

play13:13

receive here in the form of bytes so

play13:15

we're not going to decode in here we're

play13:17

going to receive whatever we receive and

play13:19

it's going to be decrypted with our

play13:21

private key

play13:25

and this result here will be decoded

play13:29

that's that so let's see before we look

play13:32

into Wireshark and package sniffing if

play13:34

that works

play13:36

so let me just split this here again

play13:37

let's go to the python directory okay

play13:40

wrong one again I changed the binding

play13:42

recently which I have a different

play13:44

functionality so I'm gonna navigate here

play13:52

and then I'm gonna run

play13:54

main py again

play13:56

run main py again I want to host here

play14:01

I want to connect here

play14:03

test

play14:05

hey okay so you can see everything is

play14:07

clear text even though it's encrypted

play14:09

actually and now let's see what the

play14:11

actual difference is because right now

play14:13

we just had the same functionality as

play14:15

before but what changed behind the

play14:17

scenes

play14:18

so for that we're going to open up

play14:20

Wireshark if you don't have Wireshark

play14:21

you need to install it the installation

play14:23

process is not too complicated you just

play14:25

download Wireshark and you run it and

play14:27

then what you can do is you can capture

play14:29

certain interfaces so I can go to

play14:30

options here I can choose an interface

play14:32

usually of course you would want to

play14:34

choose Ethernet or Wi-Fi or something

play14:37

but since this is happening here on the

play14:39

same machine so since I'm sniffing and

play14:41

listening on the same machine I will go

play14:43

with the loop back traffic because at

play14:46

the end of the day I'm sending myself

play14:48

some messages on localhost so I'm going

play14:50

to start this network here and you can

play14:52

see now packages are being sent all the

play14:54

time for all sorts of reasons you don't

play14:58

have to look at everything here but uh

play15:00

let's briefly just disable the

play15:04

encryption so we're going to say

play15:07

they can still exchange keys but we're

play15:09

not going to encrypt the messages we're

play15:11

just gonna receive and decode

play15:16

and we're going to just

play15:18

send without encryption

play15:23

and then we're going to see how easy it

play15:25

is to get the content of these uh

play15:28

packages so I'm going to run here

play15:30

again maybe I should leave this open

play15:41

there you go Main

play15:44

Main

play15:47

and now I'm going to say I want a host

play15:49

here I'm gonna connect here and now I'm

play15:51

gonna say hello world

play15:54

what is up

play15:57

My secret is that I love Matlab

play16:03

but I am afraid

play16:06

to admit rightfully so uh let's go into

play16:10

Wireshark and let's see if we can see

play16:13

some packages I can stop capturing now

play16:15

and you can see here that we have some

play16:18

packages from this IP to this IP so not

play16:21

just from localhost localhost but from

play16:23

specifically this IP to this IP and if I

play16:25

click on it you can see that I see

play16:27

something that no one wants to see

play16:29

someone confessing his love to Matlab

play16:31

and you can see my secret is that I love

play16:33

Matlab but I'm afraid to admit it or to

play16:36

admit you can see I just listened to the

play16:39

packages and this package contains data

play16:42

58 bytes and this is clear text I can

play16:45

just read what's in it now we have a

play16:47

second package here with some other data

play16:49

and we should have more packages

play16:51

containing more messages here I can see

play16:53

what is up

play16:55

then I can see here hello world so you

play16:58

can see I can just look at the packages

play17:00

with Wireshark and see what's happening

play17:02

let's do the same thing now with the

play17:04

encrypted

play17:06

um lines of code

play17:10

so now we encrypt every message and we

play17:12

decrypt every message and I can run this

play17:14

again so I can

play17:18

uh okay I cannot close this I have to

play17:20

restart this

play17:22

sorry about that

play17:25

let's navigate there again

play17:36

I'm going to run main py here I'm going

play17:38

to run main py here host connect and now

play17:43

let's run Wireshark again options

play17:47

loopback start continue without saving

play17:51

listens again to some packages and now I

play17:54

can just go ahead and type some messages

play17:57

hello world

play18:00

how are you

play18:03

I am afraid to admit that I code in

play18:09

Matlab

play18:11

and now we can go to Wireshark again we

play18:13

can stop the capturing and we can look

play18:15

at the same packages so let's look again

play18:18

there you go here we have again Source

play18:21

the IP address and destination the IP

play18:23

address if I click on it you can see now

play18:25

I still have data but it's always going

play18:27

to be 128 bytes and I cannot see what's

play18:30

in it so I can I cannot read any of that

play18:32

content here and we can also look at the

play18:34

other packages so I can scroll up here

play18:36

we have

play18:37

another message again 128 bytes no

play18:41

chance to see what's in there so I I

play18:43

don't know I cannot see the content of

play18:45

this message

play18:47

um I don't know actually what would

play18:49

happen if I include a very long message

play18:51

probably I would have some uh problems

play18:55

let's try maybe we can find out I mean

play18:57

actually I stopped capturing right

play18:59

but you can see the difference you can

play19:00

see that we can no longer just sniff the

play19:03

network connection we can no longer just

play19:04

listen to the connection and see what

play19:06

two clients are communicating about

play19:08

because we only get some random bytes

play19:11

that we don't know

play19:12

how to interpret now I'm going to send a

play19:15

bit more content maybe we're going to

play19:18

get either an error or maybe we're going

play19:21

to get larger packages or we're going to

play19:23

get 128 again

play19:27

uh

play19:28

okay no overflow error okay but you can

play19:32

see the difference you can see that when

play19:33

we encrypt the messages for our clients

play19:36

there's no difference in experience but

play19:39

we are not able to just listen to the

play19:42

connection and see what they're talking

play19:43

about which is very good because now we

play19:46

have a little bit more security as long

play19:48

as you keep the private key private it's

play19:49

basically impossible to uh to

play19:54

unencrypt these messages and this is how

play19:56

you do that this is how you build an

play19:58

encrypted chat in Python all right so

play20:00

that's it for today's video I hope you

play20:01

enjoyed it and hope you learned

play20:03

something if so let me know by hitting a

play20:04

like button and leaving a comment in the

play20:06

comment section down below and of course

play20:07

don't forget to subscribe to this

play20:09

Channel and hit the notification Bell to

play20:10

not miss a single future video for free

play20:12

other than that thank you much for

play20:13

watching see you next video and bye

play20:23

thank you

play20:26

foreign

play20:28

[Music]

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Python ProgrammingEncrypted ChatRSA EncryptionSecure CommunicationNetwork SecurityWireshark TutorialAsymmetric EncryptionSocket ModuleThreadingTCP Chat