diff --git a/README.md b/README.md index 29f30332f6d64d622c4ded2414e3e0e28737dedb..af6b11b02c06d3d2cf82d3b57601f85f37f828f4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -TASK 1 +## TASK 1 -UDP Client for IoT Server +## UDP Client for IoT Server -Description +## Description This project is a simple Python script that acts as a UDP client. It connects to a server, receives base64 encoded UDP packets, decodes them, and prints the extracted information. The client can be useful for testing and debugging UDP servers, especially those that communicate using base64 encoded packets. -Features include: +## Features include: UDP connection Base64 decoding @@ -18,7 +18,7 @@ Installation Requirements Python 3.x -Steps +## Steps Make sure you have Python installed on your system. You can download Python from here. Clone this repository or download the Python script udp_client.py. @@ -28,7 +28,7 @@ Open a terminal and navigate to the directory containing the script. Run the scr The script connects to a server running on localhost at port 5612, receives a base64 encoded UDP packet from the server, decodes the packet, and prints the decoded packet and extracted fields (Source Port, Destination Port, Length, Checksum, Payload). -How to Run +## How to Run 1. Make sure you have Python installed on your system. You can download Python from [here](https://www.python.org/downloads/). @@ -55,3 +55,75 @@ Once started, the script will: The script continues to receive, decode, and print packets until it receives an empty packet from the server, at which point it closes the socket and ends. + + + + + +## TASK 2 + +# UDP Checksum Computation + +This module provides a function to compute the checksum for a UDP packet. The UDP checksum is used to verify the integrity of the packet by performing a one's complement calculation on the packet data. + +## Description + +The `compute_checksum` function takes the source port, destination port, and payload of a UDP packet as input and computes the corresponding message's checksum. The function follows the UDP checksum algorithm to calculate the checksum value. The computed checksum can be used to verify the integrity of the UDP packet during transmission. + +## Function + +The module includes the following function: + +compute_checksum(source_port: int, dest_port: int, payload: bytearray) -> int +This function takes the source port, destination port, and payload of a UDP packet as input and computes the corresponding message's checksum. The parameters are defined as follows: +source_port: An integer representing the source port of the UDP packet. +dest_port: An integer representing the destination port of the UDP packet. +payload: A bytearray object containing the payload data of the UDP packet. +The function returns the computed checksum as an integer. + +## How to Run + +To run the script and compute the UDP checksum, follow these steps: + +1. Make sure you have Python installed on your system. This script requires Python 3. + +2. Download or clone the repository to your local machine. + +3. Import the `udp_checksum` module in your Python script or interactive shell: + ```python + from udp_checksum import compute_checksum + ``` + +4. Call the `compute_checksum` function with the appropriate parameters: + ```python + source_port = 2 + dest_port = 1 + payload = bytearray(b'AB') + + checksum = compute_checksum(source_port, dest_port, payload) + ``` + +5. The `checksum` variable will contain the computed checksum value. + +6. You can use the computed checksum to verify the integrity of UDP packets in your networking application or further processing. + +## Example + +Here's a complete example demonstrating the usage of the `compute_checksum` function: + +```python +from udp_checksum import compute_checksum + +source_port = 2 +dest_port = 1 +payload = bytearray(b'AB') + +checksum = compute_checksum(source_port, dest_port, payload) +print(f"Checksum: {checksum}") +``` + +Output: +``` +Checksum: 65489 +``` +.