Project briefing illustration for whitespace decoder: a flat tactical intelligence sheet in the style of Star Fox Assault.
ACADEMIC PROJECT / Computer Science Course

C Whitespace Message Decoder

I restored the period-and-space decoder by keeping its source-defined bit mapping and working through lookahead, EOF, incomplete bytes, and the old fixed-buffer limit.

CParsingBit operationsStreamingArchive restoration

Why I returned to the spacing decoder

I wanted to recover the small encoding convention in this C program: one literal space immediately after a period represents zero, two represent one, and three or more end the message. I assemble eight bits into a byte, most-significant bit first. Those simple rules gave me a compact way to work through streaming-parser boundaries.

I followed the period-and-space convention in the February 2024 source because the original assignment prompt was not recovered. In October 2026, I retained that mapping and worked through lookahead, end-of-file handling, incomplete bytes, and the old fixed-buffer limit.

THE CHALLENGE

The challenge: retaining the next character

PROJECT STEPS

How I decode without losing lookahead

Project briefing illustration for whitespace decoder: a flat tactical intelligence sheet in the style of Star Fox Assault.
STEP 01 OF 05
Find a period

In my restored decoder, I skip unrelated characters until I find a period that could begin an encoded spacing pattern. I treat only the spaces immediately after that period as meaningful, following the recovered convention. A period with no following spaces contributes no bit, keeping other punctuation and whitespace out of the encoded data.

Select a step to follow the project.
Read all step descriptions
  1. Find a period

    In my restored decoder, I skip unrelated characters until I find a period that could begin an encoded spacing pattern. I treat only the spaces immediately after that period as meaningful, following the recovered convention. A period with no following spaces contributes no bit, keeping other punctuation and whitespace out of the encoded data.

  2. Count literal spaces

    I count ordinary ASCII space characters immediately after each period: one means the bit zero, two mean the bit one, and three or more end the message. I stop increasing the count at three because a longer run has the same meaning. I preserve this exact convention, so tabs and other whitespace cannot replace spaces.

  3. Retain lookahead

    When a space run ends, I save the first non-space character and examine it next, because it could be another period carrying the next bit. Keeping this one-character lookahead lets me handle adjacent runs without storing the whole message. I also read characters into an int, an integer type, so ordinary characters stay distinguishable from the special end-of-file value.

  4. Assemble eight bits

    I build each byte, an eight-bit value, by moving its accumulated bits left and putting the new bit in the lowest position, then output and reset it after eight bits. These integer operations preserve the source’s order, which reads the highest-value bit first. I check generated input examples against independently known plain text so the decoder does not supply its own expected answers.

  5. Resolve termination

    I stop at end-of-file or the three-space ending marker, and report an incomplete byte with exit code 2, the program’s failure status for this case. I label this as a restoration decision because the original assignment prompt is missing. Complete bytes already sent to standard output, the program’s output stream, remain there; a caller needing the whole message or nothing must store that output separately before releasing it.

Restored parser: preserve lookahead, assemble complete bytes, and handle termination explicitly.

I begin decoding whenever the stream reaches a period. I count the immediately following literal ASCII spaces, turn a qualifying run into a bit, and continue scanning. A period without following spaces contributes nothing; tabs and other whitespace cannot stand in for spaces.

I only need three count states: one, two, or at least three. After the count reaches three, a larger value cannot change its meaning, so I cap the counter there instead of representing an arbitrarily long run.

The lookahead constraint was the subtle part I had to work through. To learn that a space run has ended, I have already read its next character; discarding it could skip an adjacent period and lose the next encoded bit. I retain that character as the next input under consideration. One-character lookahead solves the problem without buffering the whole message.

How I kept EOF distinct from input

I keep getchar's return value in an int because it must represent every unsigned-character value and the separate EOF result. Storing it directly in char can lose that distinction on some implementations.

In the repaired parser, I check for end-of-file before treating the integer as a character. That small type change makes the loop's stopping condition reliable instead of depending on whether plain char happens to be signed on the compiling machine.

How I assembled bytes with integer operations

I assemble each accepted bit by shifting the accumulator left once and filling its low bit. After eight bits, I emit the byte and reset both the accumulator and the bit count. The core update is:

Illustrative c example
byte = (byte << 1) | bit;

I use this bounded excerpt to explain the conversion without publishing the full recovered solution. It replaces floating-point powers of two with the direct integer operation the encoding requires.

For a conceptual example, I use A, whose bit pattern is 01000001. Its eight period-led runs have space counts 1, 2, 1, 1, 1, 1, 1, 2. Visible boxes can make those spaces easier to inspect than proportional-font text, but I treat boxes only as explanatory notation; actual encoded input uses literal spaces.

How I defined an unfinished byte

I also had to define what happens when the stream ends with fewer than eight bits, either at EOF or at the terminator. Because the prompt is unavailable, I identify this as a repair decision: report an incomplete byte and return exit code 2.

I leave complete bytes already emitted on standard output. That means a nonzero exit does not imply empty output. If a caller wants all-or-nothing behavior, it must buffer output separately before accepting it; my decoder itself remains a constant-space stream processor.

I add a final newline in the console example and account for it when comparing exact output bytes. I describe the convention as a small text-oriented encoding, with no encryption or robust steganographic security claim.

How I checked encoding independently

I check the parser with generated fixtures whose plaintext is known independently. A separate verification script converts each expected ASCII character to eight bits, writes the corresponding period-and-space runs, and passes them to the compiled decoder. I compare the result with the original plaintext rather than deriving expectations from the decoder under test.

The recorded round trips cover one character, a greeting, all printable ASCII characters, and a 2,048-character message that exceeds the old fixed buffer's capacity. I also check adjacent periods, an empty stream, and a partial byte. Together those cases target bit order, retained lookahead, clean termination, and removal of the arbitrary input-size ceiling.

What I repaired and learned

I replaced unsafe character/EOF handling, removed the fixed 1,000-element buffer and floating-point conversion, retained lookahead, and added explicit incomplete-byte reporting and generated tests. I kept the original period/space mapping.

I learned to describe a parser's control state as carefully as its bit arithmetic. Without the prompt, I keep partial-byte and adjacency rules labeled as restoration decisions, so the project remains a useful parser case study without implying that I recovered every original course requirement or attribution detail.

PROJECT WALKTHROUGH

I retained the source-defined period/space mapping and repaired the streaming parser in October 2026, including EOF handling, incomplete bytes, and the fixed-buffer limit.

Validation & limitations

  • I retained the source-defined period/space mapping and repaired the streaming parser in October 2026, including EOF handling, incomplete bytes, and the fixed-buffer limit.

Project records

  • Project artifacts and historical records, February 2024, approximate month
  • Restoration and public documentation, October 1, 2026
END OF PROJECT FILE RETURN TO ARCHIVE