-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
33 lines (29 loc) · 835 Bytes
/
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
#!/usr/bin/env python
import socket
import os
from Crypto.Cipher import ARC4
host = 'localhost'
port = 1337
key = '12345'
def rtext():
return os.urandom(4).encode('hex')
def encrypt(data):
return ARC4.new(key).encrypt(data)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
plaintext = rtext()
s.send(plaintext) #sending plaintext
print 'sent: ', plaintext.encode('hex')
data = s.recv(1024) #receiving cipher text from server
print 'Received:', data.encode('hex')
ptext = ARC4.new(key).decrypt(data) #printing by decrypting
print 'decrypted data:' + ptext
if(ptext == plaintext):
print 'server authenticated.'
data = s.recv(1024)
if data:
print 'received', data.encode('hex')
cip = encrypt(data)
if(s.send(cip)):
print 'sent encrypted data: ', cip.encode('hex')
s.close()