#include <stdio.h>
#include <stdlib.h>

int hex(int c0, int c1)
{
    int c = 0;

    if (c0 >= '0' && c0 <= '9')
        c = (c0 - '0') * 16;
    else
        c = ((c0 | 0x20) - 'a' + 10) * 16;

    if (c1 >= '0' && c1 <= '9')
        c += c1 - '0';
    else
        c += (c1 | 0x20) - 'a' + 10;

    return c;
}

int main()
{
    char* q = getenv("QUERY_STRING");
    printf("Content-Type: text/html; charset=utf-8\r\n\r\n");
    while (*q) {
        if (*q == '%') {
            int c0, c1, c;
            ++q;
            c0 = *q++;
            if (!c0) return 1;
            c1 = *q++;
            if (!c1) return 1;
            putchar(hex(c0, c1));
        } else {
            putchar(*q++);
        }
    }
    return 0;
}

