-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sendMessage.py
More file actions
61 lines (43 loc) · 1.48 KB
/
test_sendMessage.py
File metadata and controls
61 lines (43 loc) · 1.48 KB
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
57
58
59
60
61
import socket
import mainFunctions
#server information
HOST = "vlbelintrocrypto.hevs.ch"
port = 6000
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def send_message():
#envoi
msg = ""
txt_encoded = ""
key = "ISC"
msg_type = input("Entrez un type de message : (t,i,s) : ")
msg = str.encode(key + msg_type)
txt = input("Entrez votre texte : ")
#Connaitre type d'encodage
encoding_type = input("Entrez un type d'encodage : (shift, xor) : ")
if encoding_type == "shift":
shift = int(input("Entrez un nombre pour le décalage : "))
txt_encoded = mainFunctions.string_toListInt(txt)
txt_encoded = mainFunctions.shifter(txt_encoded,shift)
elif encoding_type == "xor":
nb = int(input("Entrez un nombre pour le xor : "))
#msg = mainFunctions.string_toListInt(msg)
#msg = mainFunctions.xor(msg,nb)
else:
print("Type d'encodage non reconnu")
# adaptation nombre de caractère
longueur_txt = len(txt)
nb_char = longueur_txt.to_bytes(2,"big")
txt_encoded = mainFunctions.listInt_toString(txt_encoded)
final_text = mainFunctions.word_to_bytes(txt_encoded)
msg_final = msg + nb_char + final_text
sock.send(msg_final)
sock.connect((HOST,port))
cont = True
while cont :
send_message()
print("Send a new message ?")
txt2 = input("y/n : ")
if txt2 == "n":
cont = False
print("End of the communication")
sock.close()