After your day off, you report to duty just as some drama starts to occur on the ship bridge. The communications officer is reporting an incoming message on the emergency frequency! It sounds like a ship might be in trouble!
The emergency frequency uses its own customised networking protocol, designed specifically for emergencies. Unfortunately the last update to your communications computer broke the receiving software for it, so you are going to need to quickly write your own. The emergency network protocol is a simplified protocol compared to other networking protocols like TCP/IP.
The protocol used divides transmission into 256-bit packets using the following structure:
Decode the incoming message (your input data) and submit the reassembled message as your answer.
Consider the following two packets, shown in their hexadecimal representation.
55550000005800f754686973206973206120746573742e205468697320697320
55550000005801f06120746573742e205468616e6b796f752e20202020202020
The process to decode these packets follows:
54-68-69-73-20-69-73-20-61-20-74-65-73-74-2e-20-54-68-69-73-20-69-73-20
. Take this data one byte at a time, adding them together.Hex 54 = Decimal 84
Hex 68 = Decimal 104
Hex 69 = Decimal 105
Hex 73 = Decimal 115
Hex 20 = Decimal 32
... continued to the end. When you sum these values together, they total to 2039. To calculate the correct checksum then, 2039 % 256 = 247, which is represented in hexadecimal as F7. This matches the content of the checksum byte so we know the packet is valid. Discard any packets with an invalid checksum.
Both packets are valid according to their checksum.
Payload for sequence=0 is 54686973206973206120746573742e205468697320697320
Payload for sequence=1 is 6120746573742e205468616e6b796f752e20202020202020
Combined message payload is 54686973206973206120746573742e2054686973206973206120746573742e205468616e6b796f752e20202020202020
54686973206973206120746573742e2054686973206973206120746573742e205468616e6b796f752e20202020202020
T h i s i s a t e s t . T h i s i s a t e s t . T h a n k y o u .
This is a test. This is a test. Thankyou.
.Decode the incoming message (your input data) and submit the reassembled message as your answer.
T
and ends with a .
)