Decoding a String

Difficulty: Medium

The task for last month’s Exercise was to encode a string. As you may have feared, the task for this month’s Exercise is to decode that string. Let me review:

The method for string encoding presented last month works like this:

  1. Translate a character (or byte) into its two-digit hexadecimal value.
  2. Translate the next character into a two-digit hex value minus the first character’s value.
  3. Repeat Step 2 until all the data is processed.

To obtain the original string, you must work backwards: The first character’s ASCII code value is represented as a two-digit hex value. The next character is the difference between the first and second characters, again represented as a two-digit hex value. Each subsequent character is the same: the difference between the current character and the previous one. But this math isn’t the most difficult part of the puzzle.

No, another perhaps unforeseen problem is ensure that you properly interpret the two-digit hex values.

As with last month’s Exercise, for this month’s Exercise you must create a filter. The filter reads standard input and converts the hex digits into characters. You can test your solution on the string presented at the start of last month’s Exercise:

48190F0009A72827FDFDFBFD18FAAD460CFDFEB323EA192903BB1731F800FCFC0E97

When I run this string through my solution, I see this output:

Happy Holidays from C-For-Dummies

Aw. 🥰

Click here to view my solution, though please try this Exercise on your own rather than see what I did first.

Leave a Reply