Packet Sniffer
[Credit: Consortium for Computing in Small Colleges, Programming Contest, adapted]
-
- Sniffed any good packets lately, dude? Hopefully you haven't done this illegally, but rest assured that there are some who have. If you surf the internet, you have probably visited companies' net sites where they sell their products online: you give them your credit card number and they ship you the goods. That's a convenient way to shop if you can ensure that your credit card number isn't being "sniffed" up by wily hackers and used illicitly.
-
- The Internet is an example of a packet-switched network. This means that information is sent in discrete groups of bits called packets from computer to computer. For example, when I send e-mail to someone in the Philippines, my message (at the binary level) is broken up into packets, and routed packets by packet (not all at once or even along the same route) from computer to computer, ultimately to reach the recipient's computer.
- "Packet sniffing" refers to writing a program that grabs the individual packets that come your computer's way and reads the contents. Now the term "packet sniffing" has obvious unethical connotations: usually it refers to writing a program that reads packets addressed to computers other than your own. But the principal is exactly the same when you only intercept those packets that are intended for you.
-
- Let's suppose a network packet consists of five parts:
- a special start-of-packet bit pattern, [ 1000001 ]
- a packet ID, [ 7 bits ]
- the packet sequence number, [7 bits ]
- the packet content, [ max 3 X 7-bits ]
- and a special end-of-packet bit pattern. [ 1000001 ]
- Suppose that the start- and end-of-packet pattern are both "1000001" and that the packet contains no more than 3 consecutive sequences of 7 bits. So, to write the program to "sniff" packets, you only need to be able to write a program that scans its input and "decodes" everything between the pairs of "1000001"
-
- For this program assume that the content of each packet is binary representation of no more than three ASCII characters, each encoded in 7 "bits" (0's and 1's). Your task is to write a program that gathers, reassembles and prints out the message (in English) that is being transmitted by a set of packets. Note that packets may not "arrive" in the right order and that some packets may be received that are not part of the message you are "sniffing".
-
- Sample Input:
- Each sample file contains at least one complete message. The file may contain up to 127 messages. All input files can be read as text, and consist of a single integer followed by a series of 1's and 0's. There are only 2 line breaks in the entire input file:
- After the first value, which is a number identifying the message you are trying to encode.
- At the end of the file
- 0
100000100000000000000110001011011111101111100000110000010000000000000101000011000001
-
The correct output for the sample input above is:
- boo!
- The following is output as produced by a sample solution [ called "reader" in /home/233/Bonus/Packet ]: (It displays each packet as it is decoded: message number, packet number, and then the characters in the packet followed by "-|". Message number marked with "*" are those belonging to the message we are trying to "sniff".)
- File name: asst.txt
- File open.
Looking for message# : 0
m 0*,p 0= boo-|
m 0*,p 1= !-|
Message:
boo!
Done.
- You are guaranteed 2 things:
- the encoding is correct, and
- there will be no upper case letters (especially not 'A') encoded in the packet.
- Your program may print directly to the screen.
--DATA FILES in www.ucalgary.ca/~beckerk/Courses/CS-101/Asst/PacketSnifefrs/Code/ --