Problem 2: Bit Oriented Protocols

Background:

One way to send information from one machine to another is to use a bit stream broken down into frames. Each frame starts and ends with a specific flag, namely 01111110 (0, 6 ones, 0). Since the flag may come up as a valid byte to send in a message, we'll employ bit stuffing. That is, whenever 5 consecutive ones are seen in the message, the sender inserts a 0, then continues on. The receiver has to remove that, so when the receiver sees 5 ones, it has to look at the next bit. If the next bit is a 0, the 0 is ignored, and the receiver continues on. If the next bit is a 1 followed by a 0, the receiver has gotten the flag to signify the end of a frame.

Input:

The input will be a bit-stuffed bit stream representing frames sent to you. The stream may span multiple input lines. No singe line of input will be longer than 80 characters. There may be extraneous bits in the bit stream (ie, bits that are not apart of a frame). These should be ignored. There are no blank lines in the input.

Output:

Your program is to take the bit stream, unstuff it, and print the resulting message. We'll use the 8-bit ASCII table for the conversions. After printing the message, your program should print 2 newline characters then go onto the next message.

Sample input:

01111110011000010110110000100111011
1010001101000011011110111001001111110
0101010101111110
011010000110111101110111011001000111100100001010
01111110

Sample Output:

al'thor

howdy