Feature #1: Validate Packet Structure
Explore how to validate network packet structures using bit manipulation, focusing on encrypted packets ranging from one to four bytes. Understand the protocol rules, packet formats, and how to check data integrity efficiently, preparing you for real-world cyber security challenges.
We'll cover the following...
Description
We use a network protocol that encrypts all packets using a proprietary scheme. The encryption scheme dictates the size of an individual packet, i.e., the packet size ranges from 1 to 4 bytes, and each packet follows a specific structure:
- For a
1byte packet, the first bit of the packet is0, followed by the remaining bits of the packet’s content. - For an
n-bytespacket, the firstnbits are all1s, then + 1bit is0, followed byn - 1bytes, with the most significant2bits being10.
A sequence of packets is given as an array of integers representing the decimal values of each byte in the packets. We need to verify that the packet stream has not been tampered with.
The packet number range and its binary representation can be reviewed here:
| Packet number range (hexadecimal) | Octet sequence (binary) |
|---|---|
| 0000 0000 - 0000 007F | 0xxxxxxx |
| 0000 0080 - 0000 07FF | 110xxxxx 10xxxxxx |
| 0000 0800 - 0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx |
| 0001 0000 - 0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
Note: The input array is in the form of integers. We only consider the
8...