-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
56 lines (41 loc) · 1.18 KB
/
server.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
import socket
from termcolor import colored
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
def encrypt(info):
msg = info
BLOCK_SIZE = 16
PAD = "{"
def padding(s): return s+(BLOCK_SIZE-len(s)) % BLOCK_SIZE*PAD
cipher = AES.new(hkey, AES.MODE_ECB)
result = cipher.encrypt(padding(msg).encode('latin-1'))
return result
def decrypt(info):
msg = info
PAD = "{"
decipher = AES.new(hkey, AES.MODE_ECB)
pt = decipher.decrypt(msg).decode('latin-1')
pad_index = pt.find(PAD)
result = pt[:pad_index]
return result
so = socket.socket()
host = socket.gethostname()
port = 8000
so.bind((host, port))
print(colored("[+] server is live..", "green"))
so.listen(5)
print(colored("[+] waiting for connection..", 'green'))
c, addr = so.accept()
print("[+] connected to ", addr)
password = input(colored("Enter the key/password: ", 'red'))
hash = SHA256.new()
hash.update(password.encode('utf-8'))
hkey = hash.digest()
while True:
message = input('send: ')
message = encrypt(message)
c.send(message)
print(colored("listening..", 'green'))
message = c.recv(1024)
message = decrypt(message)
print("rev: ", message)