Skip to content

Instantly share code, notes, and snippets.

@munho
Forked from xsleonard/gist:7341172
Created December 18, 2024 05:45
Show Gist options
  • Select an option

  • Save munho/035118538cabd987fa636d67fd8182b5 to your computer and use it in GitHub Desktop.

Select an option

Save munho/035118538cabd987fa636d67fd8182b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @xsleonard xsleonard created this gist Nov 6, 2013.
    12 changes: 12 additions & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    unsigned char* hexstr_to_char(const char* hexstr)
    {
    size_t len = strlen(hexstr);
    IF_ASSERT(len % 2 != 0)
    return NULL;
    size_t final_len = len / 2;
    unsigned char* chrs = (unsigned char*)malloc((final_len+1) * sizeof(*chrs));
    for (size_t i=0, j=0; j<final_len; i+=2, j++)
    chrs[j] = (hexstr[i] % 32 + 9) % 25 * 16 + (hexstr[i+1] % 32 + 9) % 25;
    chrs[final_len] = '\0';
    return chrs;
    }