-
Notifications
You must be signed in to change notification settings - Fork 6
/
chat_client.py
71 lines (54 loc) · 2.33 KB
/
chat_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#By SxNade
#https://github.com/SxNade/Terminal_chat
#CONTRIBUTE
#client script
from termcolor import colored
from Crypto.Cipher import AES
import socket
import os
banner = '''
_____ _____ ____ __ __ ___ _ _ _ _ ____ _ _ _ _____
|_ _| ____| _ \| \/ |_ _| \ | | / \ | | / ___| | | | / \|_ _|
| | | _| | |_) | |\/| || || \| | / _ \ | | _____| | | |_| | / _ \ | |
| | | |___| _ <| | | || || |\ |/ ___ \| |__|_____| |___| _ |/ ___ \| |
|_| |_____|_| \_\_| |_|___|_| \_/_/ \_\_____| \____|_| |_/_/ \_\_|
*By SxNade https://github.com/SxNade
'''
print(banner)
#Receiving The Value Of IP and PORT From the User
SERVER_IP = input(colored("What Is Ip of the server running: ", "green"))
SERVER_PORT = int(input(colored("Enter Port No on which the server is running: ", "green")))
USER_NAME = input(colored("Please Choose a Username for Chat: "))
os.system('clear')
print(colored("<1>ONLINE..", "green", attrs=['reverse', 'blink']))
name = USER_NAME + ">> "
encoded_name = name.encode()
# chat Fucntion Initiates the Connection to the Server
def chat():
s = socket.socket()
#connecting to the chat server
s.connect((str(SERVER_IP), SERVER_PORT))
#infinite loop to recieve messages from the user till the server runs
while True:
#adding AES encryption
magic = AES.new('EBC3D4C51C46801A7267AAB59A63551B', AES.MODE_CFB, 'This is an IV456')
#YOU MUST REPLACE THIS AES KEY>>>FIND A AES KEY FOR YOURSELF ON GOOGLE>>>!!
In_msg = s.recv(8192)
recv_data_1 = magic.decrypt(In_msg)
recv_data_unenc = recv_data_1.decode()
print("\n" + recv_data_unenc)
Out_msg = input(colored("\nSEND-> ", "red", attrs=['bold']))
data = encoded_name + Out_msg.encode()
send_data = magic.encrypt(data)
#encrypting the data with AES
s.send(send_data)
#condition statement to close the chat incase server_user enters 'bye'
if recv_data_unenc == 'bye':
os.system('clear')
print(colored("<0>OFFLINE", "red", attrs=['bold']))
s.close()
break
#Final Main function to run the Chat Program!
def main():
chat()
main()