0

I want to know how I can encrypt and decrypt file transfer by using crypto AES encryption. In this example I can transfer a print screen but I need to crypte sending and decrypt recieving.

Client:

import socket
import sys
from PIL import ImageGrab
s = socket.socket()
s.connect(("10.10.10.10",9999))
img=ImageGrab.grab().save('screen.png')
f=open ("screen.png", "rb")
l = f.read(1024)
while (l):
    s.send(l)
    l = f.read(1024)
s.close()

server:

import socket
import sys
s = socket.socket()
s.bind(("10.10.10.10",9999))
s.listen(10)

i=1

while True:
    sc, address = s.accept()
    print address
    f = open('file_'+str(i)+".png",'wb') #open in binary
    i=i+1
    print(i)
    l = 1
    while(l):
        l = sc.recv(1024)
        while (l):
            f.write(l)
            l = sc.recv(1024)
        f.close()    
    sc.close()
s.close()
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
nater303
  • 85
  • 2
  • 14

0 Answers0