-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path008-UDP-chat-server-ROT13.py
33 lines (25 loc) · 1.02 KB
/
008-UDP-chat-server-ROT13.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
import socket
import string
def rot13(msg):
# Create a translation table to use for the encoding
trans_table = msg.maketrans(string.ascii_lowercase + string.ascii_uppercase,
string.ascii_lowercase[13:] + string.ascii_lowercase[:13] +
string.ascii_uppercase[13:] + string.ascii_uppercase[:13])
# Use the translate method to encode the message
enc_msg = message.translate(trans_table)
return enc_msg
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 10001))
print("CommServer initiated on port 10001. Prepare for incoming enemies.")
while True:
# get words
data, addr = sock.recvfrom(1024)
msg data.decode()
print(f"Discovered a transmission from {addr}: {msg}")
# send em back
response = input("Speak now:)
enc_response = rot13(response)
sock.sendto(encoded_response.encode(), addr)
if __name__ == '__main__':
main()