Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #coding: utf-8
- import socket
- import sys
- import time
- from Crypto.Cipher import XOR
- import base64
- import binascii
- import threading #fix
- ######lo compiliamo assieme questo###
- keyz = "sdhsfd3434YYAI@pogna" #
- ip = "51.178.52.91" #
- #####################################
- #incorrect padding
- #keyboard interrupt
- #login, who, auth, part
- try:
- username = sys.argv[1]
- except IndexError:
- print("Utilizzo: python client_chat.py nickname")
- exit()
- def encrypt(msg, key):
- key = key
- cipher = XOR.new(key)
- encrypted_msg = base64.b64encode(cipher.encrypt(msg))
- return encrypted_msg.decode("utf-8")
- def decrypt(crypted_msg, key):
- key = key
- cipher = XOR.new(key)
- try:
- decrypted_msg = cipher.decrypt(base64.b64decode(crypted_msg))
- except binascii.Error:
- return crypted_msg
- except TypeError:
- return crypted_msg
- return decrypted_msg
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- s.connect((ip, 8934))
- except socket.error:
- print("Controlla la connessione.")
- exit()
- def read(): #fix
- while True: #fix
- data = s.recv(1024) #fix
- user = data.split(":")[0] #fix
- try:
- msg = decrypt(data.split(":")[1].strip(), keyz) #fix
- if "[104]" in data:
- user = data.split(":")[1]
- print("{} connesso".format(user))
- else:
- print("<{}>: {}".format(user, msg)) #fix
- except IndexError:
- print(data)
- def write(): #fix
- message = raw_input() #fix
- time.sleep(0.1)
- s.send(encrypt("{}:{}".format(username,message),keyz)) # fix
- t = threading.Thread(target=read, args=[]) #fix
- t.setDaemon(True)
- s.send(encrypt("{}:{}".format(username,"!hello!3498758972389712387"),keyz))
- #fix
- try:
- t.start() #fix
- while True:
- write() #fix
- except KeyboardInterrupt:
- print("Programma interrotto dall'utente (ctrl+c)")
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement