Lecture Notes - Decryption in WP2 and BSD Sockets

Lecture Overview

  • Focus on programming software libraries.
  • Three main topics will be covered:
    • Decryption parts of WP2 (Work Package 2)
    • Advanced server and client programming
    • Introduction to protocols (discussed in future classes)

WP2 Decryption

  • Objective: Learning to decrypt using a simple transposition cipher.
  • Recap:
    • Students have encountered transposition ciphers in WP2.
    • Example ciphertext: "LNP, dots, I, G, R, V, underscore, ..."
    • This message corresponds to: "Live long and prosper."

Key Concepts

  • Matrix Building for Decryption:
    • When decrypting, create a matrix with 7 rows (for key size of 7).
    • Number of columns needed = total characters in ciphertext / 7 (rounded up).
    • Positions in matrix need to account for "empty" spaces that won’t be filled during encryption.
  • Decryption Process Steps:
    1. Calculate how many characters fit in the matrix configuration.
    2. Fill the matrix from the ciphertext, left to right, top to bottom.
    3. Read the matrix in reverse order to reconstruct the original message by transposing back.

Points on Grades for WP2

  • Completing the assignment without using in-memory matrix gets full points.
  • Use of modulus operator for indexing is required for full marks.
  • Submit up to four times to Gradescope for evaluation; improvement can be made on previous attempts.
  • Attention to error handling to avoid auto-grader deductions for exceptions raised in code.
  • Typical pitfalls:
    • Not submitting the .git folder.
    • Incorrect file naming conventions.

Networks

Review of BSD Sockets

  • Focus on server-client architecture using BSD sockets.
Server-side Workflow
  1. Create sockets for communication.
  2. Bind sockets to a network address and port.
  3. Listen for incoming connections.
  4. Accept connections and establish communication.
Client-side Workflow
  1. Create sockets for communication with the server.
  2. Connect to the server's address and port.
  3. Send messages/request, receive server responses.

Communication Flow

  • Always begins with the client initiating a connection.
  • Continues in an infinite loop until the server denies communication or the client disconnects.
  • Both sides read and respond to requests continuously.

Implementation of Code

Simple Server and Client Code Explanation

  • A prototype server code that listens for connections and callbacks.
  • Example modifications to handle assignments as services (like WP2).
  • Emphasis on code readability and modular design (avoid repetition, improve documentation, atomic functions).
  • Important to validate input (e.g., exceptions for invalid data, file not found errors, invalid keys).

Example Code Improvement Recommendations

  • Improve code style for clarity and maintainability.
  • Use atomic functions to segment functionality.
  • Incorporate comments and effective docstrings.

Encoding and Communication

  • Explain the role of encoding characters into bytes for transmission (ASCII vs. UTF-8).
    • Encoding: Mapping characters to bytes for transmission in the socket every character must be converted into bytes.
  • Protocol introduction for server and client communication:
    • The protocol determines how messages are sent and acknowledged (e.g., use of line terminators).

Classroom Activity

  • Begin coding a server and client from scratch.
    • Students may work in pairs or individually.
  • Recommendation to execute on OpenLab for consistent network functionality.

Conclusion and Next Sessions

  • Discussion on threading for concurrent connections in future classes.
  • A teaser for the next class providing insight on enhancing server capabilities for handling multiple client connections.
  • Students encouraged to submit assignments on Canvas and continue engaging with the material.
  • The basics of protocols will also be covered next week, focusing on the structured communication between a client and server, leading into discussions on a multi-threaded HTTP server in upcoming classes.