Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Created September 25, 2012 00:42
Show Gist options
  • Save JAChapmanII/3779325 to your computer and use it in GitHub Desktop.
Save JAChapmanII/3779325 to your computer and use it in GitHub Desktop.
decode block code
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
int decodeString(char *str) {
int res = 0, p10 = 1;
for(ssize_t i = strlen(str) - 1; i >= 0; --i)
res += (str[i] - '0') * p10, p10 *= 10;
return res;
}
int main(int argc, char **argv) {
char *decryptedBlock = argv[1];
size_t slen = strlen(decryptedBlock);
for(ssize_t i = slen - 3; i > -3; i -= 3) {
decryptedBlock[i + 3] = '\0';
if(i < 0)
i = 0;
printf("dBlock: %s\n", decryptedBlock + i);
char c = decodeString(decryptedBlock + i);
printf("c: %d (%c)\n", c, c);
// do stuff with c
if(!i)
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment