#P10345. Flow Segment Validation
Flow Segment Validation
Flow Segment Validation
You are given a flow segment represented as a hexadecimal string. The string encodes an Ethernet frame with a 4‐byte (8 hex digit) CRC32 appended at the end. Your task is to validate the segment by performing the following checks:
- CRC32 Check: Compute the CRC32 checksum (using the standard polynomial
0xEDB88320
) on the Ethernet frame data (i.e. all bytes except the last 4 bytes). Compare your computed 32‐bit value (expressed as 8 uppercase hexadecimal digits) with the provided CRC32 (which occupies the last 8 hex digits). They must be exactly equal. - IP Header Check (Conditional): Because every segment is an Ethernet frame, the CRC32 check is always performed. In addition, if the Ethernet type field (located in bytes 12 and 13 of the Ethernet header) equals
0800
(indicating that the payload is an IP packet), then you must also verify the IP header checksum. The IP header is 20 bytes long and immediately follows the 14‐byte Ethernet header. In the IP header the checksum field is located at byte offset 10 (covering 2 bytes). To validate the IP header checksum, replace the checksum field with 0 and compute the 16‐bit checksum as follows:</p>Divide the 20 bytes into 10 words (each 16 bits), sum them up using standard 16‐bit ones’ complement addition (adding any overflow back into the least significant bits) and take the one’s complement of the final sum. The resulting value (expressed in hexadecimal) must equal the original checksum field value from the IP header.
A segment is considered
Valid
only if the CRC32 check passes (for all segments) and, when applicable, the IP header checksum is correct. Otherwise, outputCorrupt
.inputFormat
The first line contains an integer T (the number of test cases). Each of the following T lines contains a single hexadecimal string representing a flow segment. In the string, all bytes of the Ethernet frame (including header and data) appear first, and the final 8 hex digits represent the appended CRC32 checksum.
outputFormat
For each test case, print a single line containing either
Valid
if all applicable checks pass, orCorrupt
otherwise.sample
3 0102030405060708090A0B0C88B5D202EF8D FFFFFFFFFFFF112233445566080045000014000040004006B98EC0A80001C0A8000289ABCDEF FFFFFFFFFFFF112233445566080045000014000040004006B98FC0A80001C0A8000201234567
</p>Valid
Valid Corrupt