Spring 2022 IS496 Programming Assignment 1 - Simple Secure UDP Program

Total Points: 100 points
Goal: Refresh how to compile code, gain experience with network syscalls.
    Write a simple UDP network client and server.
Assigned: January 31, 2022
Due: February 21, 2022 by the end of day (11:59 pm CST).
Grouping: To be developed by a group.
Note: This instruction is based on Python. The C/C++ version is available here.


You will be writing a simple and secure communication protocol using UDP client and server. The program will build a UDP connection between two hosts and exchange encryption keys. The client will then send an encrypted message to the server. The server will decrypt the message and reply with the timestamp when it receives the message. You also need to compute the round-trip-time (RTT) of your message. More background information about public key encryption and socket programming is provided in the "Helpful Links" section at the end of this document.


Part 1: UDP Practice

In the first part of this assignment, you are asked to build a simple UDP server and client where the server can successfully 1) establish the connection with the client, and 2) send a string (e.g., "Hello World") to the client. The finished code for Part 1 can also be used for Part 2 of this assignment.

We have provided an optional starter skeleton code to get you started on the right track. The starter code files (i.e., udpserver.py and udpclient.py) can be downloaded from here. Please refer to the "Running the programs on student machines" subsection for additional details about how to test your program on the student machines.

Part 2: Simple Secure UDP Program

Write a simple UDP client that takes in:
Also write a simple UDP server that takes in:
The library pg1lib.py (provided) contains the following methods:

Generate and return an encryption key
  bytes: this host's encryption key

Encrypt a message with peer's encryption key
 message (bytes): plaintext message to encrypt
 pubkey (bytes): peer's encryption key (formatted as output to getPubKey())
 bytes: base64 encoded ciphertext
encrypt(message, pubkey)

Decrypt a message with this host's private key
 cipher (bytes): plaintext message to encrypt
 bytes: decrypted plaintext message

Calculate the checksum for the input data
 data (bytes): the data to process
 int: the checksum

Note: You do not need to implement the encryption/decryption and checksum functions listed above, as they are provided in the file pg1lib.py. You can download it from here. If you are not familiar with public key cryptography, please refer to the links provided in the "Helpful Links" section.

The following protocol is to be implemented in your assignment:
  1. The client reads the host name, port number, and the message to be sent from the user input.
  2. The client generates a public key using getPubKey(), connects to the server, and sends it its public key.
  3. The server generates its own public key (also using getPubKey()), encrypts it using the client's public key and the method encrypt(message, pubkey), and sends the encrypted key as a response back to the client.
  4. The client decrypts the server's public key (decrypt(cipher)). It then calculates a checksum for the message (using checksum(data)), and prints the checksum to the screen. It then encrypts the message using the server's public key ( encrypt(message, pubkey)). The client then sends both the encrypted message and the checksum to the server. (The checksum does not need to be encrypted as it cannot be used to reconstruct the original message.) Hint: The checksum is an unsigned long, and you will need to take into account endianness to transmit it correctly.
  5. The server receives the encrypted message as well as the checksum. It decrypts the message (using decrypt(cipher)), and prints both the message and the received checksum to the screen. Then it calculates the checksum with checksum(data) from the decrypted message, prints it, and compares it with the received checksum. If the checksum matches, the server sends a confirmation to the client (e.g., an integer of value 1). If the checksum does not match, the server reports an error message, and acknowledges the client (e.g., an integer of value 0).
  6. The client receives the response message from the server, and calculates the round-trip-time (RTT), in microseconds, from the time it sent the message to when it received a response. If the response message confirms the server has received the message without errors (e.g., an integer of value 1), print the RTT to the screen; otherwise, report an error message.
Note: a suggested buffer size is 1024 characters in this assignment. DO NOT output any debugging information, or other informational messages to the screen. Doing so will cost you points!

Running the programs on student machines

You need to run your program using a random command line string. For example:

[netid@is-student02 ~] $ python3 udpserver.py [port]

[netid@is-student00 ~] $ python3 udpclient.py [hostname] [port] [test message]

Note: The client and server should be executed on different student machines (e.g., if the server is running on student 00, then the client should be tested on student 01/02/03). You may use the port numbers assigned to any of your group members to test your code (refer to appendix A).



Create a README file that contains a complete listing / explanation of what files are present in the directory and the instructions to compile and run your code (e.g., give a command line example to test your code with a sample file or random string).

Upload a gzipped tar file containing your .py files, pg1lib.py, and your README file to the corresponding assignment on Canvas. One submission per group is sufficient. Your source code files must contain the name and netid of each group member or it will not be graded.

Note: The default version of Python 3 on student machines is 3.8.10, and is located at /usr/bin/python3. Please also specify your Python version in your readme file if your code is written a version different from Python 3.8.

Your code will be evaluated on the student 00/01/02/03 machines based on the following evaluation rubric.

Evaluation Rubric (100 pts)

The points for the assignment are as follows:

Helpful Links

*Socket Programming in Linux : Beej's Guide to Network Programming, Socket Programming in Python and UDP Socket Example in Python
*Public-key Cryptography : Public Key and Private Keys and Wikipedia Link


Use the port number corresponding to your name in the appendix below.

Table 1. Port Assignments
UDP Port to UseName
41001 Canty, Angel
41002 Guo, Jerry
41003 Lee, Ivy
41004 Shamim, Iman
41005 Shi, Tiancheng
41006 Shuaibi, Alaa
41007 Torres, Michael
41008 Xiao, Justin
41009 Cui, Cilia
41010 Donelson, Curt
41011 Fang, Hongli
41012 He, Richard
41013 He, Xiang
41014 Huang, Chung-An
41015 Huang, Houshuo
41016 Jia, Bo
41017 Jia, Hao
41018 Jiang, Yuxuan
41019 Li, Chang
41020 Li, Ziheng
41021 Liu, Amelia
41022 Liu, River
41023 Wang, Jingwei
41024 Wang, Weiyu
41025 Wang, Xiuyuan
41026 Wang, Zeyu
41027 Xia, Yilin
41028 Xu, Yuting
41029 Xu, Zhizhou
41030 Yang, Qinwen
41031 Zhang, Boyu
41032 Zhang, Jingfang
41033 Zhang, Yunjia
41034 Zhang, Zheng
41035 Zheng, Shaojun