Problem D
M3: Rover
This is the $4$th of $4$ steps in the Rover problem. The complete problem specification is on the NSA Cyber Challenge website.
In this problem, you will track the location of the rover after receiving commands from the ground station. For simplicity, we will represent the surface of Mars as a simple two-dimensional grid with coordinates $(x,y)$. The rover will begin at $(0,0)$. A “north” command will move the rover to $y=y+1$. A “south” command will move the rover to $y=y-1$. An “east” command will move the rover to $x=x+1$. A “west” command will move the rover to $x=x-1$. Only move the rover when the tag is valid AND the counter has not been used before (we want to prevent duplicate commands if a retransmission happens and to prevent replay attacks by an attacker).
Encoding
Every input and output line contains binary data encoded as a string using the “hexlify” method (named for the way Python implements it in the binascii module). The binary $32$-bit unsigned integer represented in hexadecimal as 0xDEADBEEF would simply be converted into an ASCII string “deadbeef” (always use lower-case letters). The most significant bytes come first.
Input
The first lines of the input will be the parameters to use for the rest of the input. The first line will contain the device ID (a single byte). The second line will contain the the key. The keys are $32$ bytes so they will be represented by $64$ characters. The third line is the Initialization Vector ($16$ bytes). The fourth line is the B1 Nonce ($13$ bytes). The fifth line is the B2 Nonce ($15$ bytes). The sixth line is the A0 Nonce ($14$ bytes).
After reading those initial parameters, the subsequent lines will each contain a packet of data (in the same specification as output from the $3$rd rover problem). The first byte will be the sync byte. The second byte will be the payload size. The third byte will be the device ID. The fourth and fifth bytes will be the counter. Next will be the payload (the rover command). Finally, there will be $4$ bytes of the CBC-MAC tag. Read these packets until there is no more input.
Output
For each packet received, output one line containing one string from the following list:
-
If the sync byte is incorrect, print “rover bad sync byte”.
-
If the device ID doesn’t match, print “rover wrong deviceid”.
-
If the counter has been used in a valid packet before, print “rover duplicate packet”.
-
If the CBC-MAC tag doesn’t match the packet tag, print “rover bad checksum received”. (If the checksums do match, it is a valid packet.)
-
If the command byte isn’t one of the $5$ valid commands in the specification, print “rover bad command received”.
-
If the command is “stop”, print “rover stopped at $(x,y)$”, replacing $x$ and $y$ with the current grid location of the rover.
-
If the command is “north”, “south”, “east”, or “west”, print “rover moving to $(x,y)$”, replacing $x$ and $y$ with the current grid location of the rover.
If multiple checks match a given packet, only print out the first applicable string from the list above.
Sample Input 1 | Sample Output 1 |
---|---|
65 1042e7e22dc64b089be48c2b9f31e8ac68b153d5a13843b3b490613efb8e81dc 095f272c79d7f9ac3b02b4ba9a70ab00 00040100000000000000000000 000000000000000000000000000000 01008d493b30ae8b3c9696766cfa fd01652c43c9c76fd885 fd01652c45ef01ff2eb0 df01652c45ef01ff2eb0 fd01652c45ef61ff2eb4 fd01652c45ef61ff2eb4 fd01652c4720cae56e04 fd01652c494f0ef4b9f0 fd01652c4bbabaab02f3 fd01652c4da85aa99be6 fd01652c4f7b8dcd3688 |
rover stopped at (0,0) rover bad checksum received rover bad sync byte rover moving to (0,1) rover duplicate packet rover moving to (-1,1) rover moving to (-1,2) rover stopped at (-1,2) rover moving to (0,2) rover moving to (0,3) |