Created
September 25, 2012 00:42
-
-
Save JAChapmanII/3779325 to your computer and use it in GitHub Desktop.
decode block code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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