๐Ÿ›ก๏ธ Tactical

The Handshake

Stardate 55169.9 ยท UES Magnanimous

Briefing

The other computer wants to talk properly now, and properly means framed messages: a fixed prefix, the message length, the message, and a checksum, pipes between. It will reject a frame with the wrong prefix, a length that does not match, or a checksum that does not add up, and it will say nothing about why, because it is a computer, and a computer from nineteen years in the future at that.

Chief T'Kala wants both directions: frame a message for sending, and unframe one for receiving, refusing anything malformed. Because the length is in the frame, a message may itself contain pipes and still come back whole. The checksum is the sum of the message's bytes, modulo 256, as two hex digits. Eight objectives. Lt. Skree has pointed out that if we get this wrong the other ship simply says nothing, "which is what it has mostly done, so we would not know". This is true and unhelpful.

Mission objectives

ARCHIE checks all eight every time you run diagnostics.

  • โ€ขchecksum: the byte sum modulo 256, as two lower-case hex digits
  • โ€ขchecksum: an empty message is 00
  • โ€ขframe: 'MAGN|<length>|<message>|<checksum>'
  • โ€ขunframe: a good frame gives back the message
  • โ€ขunframe: a message containing pipes survives the round trip
  • โ€ขunframe: a wrong prefix is refused
  • โ€ขunframe: a length that does not match is refused
  • โ€ขunframe: a corrupted checksum is refused
Ask Commander Raghunathan for a hint

Split on the pipe at most three times, so the message keeps its own pipes: prefix, length, then the rest, and the checksum is the last field of the rest. Use the declared length to cut the message out of the rest exactly. Refuse on any check that fails, and only then recompute the checksum and compare.

๐Ÿš€ Away mission

Away mission: make it a real protocol. Write a tiny server that accepts framed messages over a local socket (Python's socket, Rust's std::net), unframes them, and replies with a framed acknowledgement, and a client that sends three messages including one deliberately corrupted. Watch the server refuse it. Then swap the checksum for a real hash and notice how little else changes.