client.py 642B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. import socket
  3. import sys
  4. from Crypto.Cipher import AES
  5. import base64
  6. hote = "xxx.xxx.xxx.xxx"
  7. port = 79
  8. key="abcdefghijklmnop" #(sur 16 carac !)
  9. enc = AES.new(key[:32])
  10. code = "toto"
  11. def encrypt(clear):
  12. temp = (str(clear) + (AES.block_size - len(str(clear)) % AES.block_size) * "\0")
  13. crypt = base64.b64encode(enc.encrypt(temp))
  14. return crypt
  15. def decrypt(crypt):
  16. temp = enc.decrypt(base64.b64decode(crypt))
  17. clear = temp.rstrip("\0")
  18. return clear
  19. try:
  20. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  21. sock.connect((hote, port))
  22. sock.send(encrypt(code))
  23. sock.close
  24. except(socket.error):
  25. sys.exit()