Created
December 25, 2014 19:11
-
-
Save qpfiffer/c05512ece1938517bacd to your computer and use it in GitHub Desktop.
Daily programmer #171 attempt
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 <string.h> | |
static const char encoding[] = { | |
0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0, | |
0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA, | |
0,0,0,0,0,0,0, | |
0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, | |
0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, | |
0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24 | |
}; | |
static const char r_encoding[] = { | |
' ','0','1','2','3','4','5','6','7','8','9', | |
'A','B','C','D','E','F','G','H','I','J','K', | |
'L','M','N','O','P','Q','R','S','T','U','V', | |
'W','X','Y','Z' | |
}; | |
static const char *tests[] = { | |
"REMEMBER TO DRINK YOUR OVALTINE", | |
"GIANTS BEAT DODGERS 10 TO 9 AND PLAY TOMORROW AT 1300 ", | |
"SPACE THE FINAL FRONTIER THESE ARE THE VOYAGES OF THE BIT STREAM DAILY PROGRAMMER TO SEEK OUT NEW COMPRESSION" | |
}; | |
struct encoded { | |
const unsigned int character : 6; | |
} __attribute__((__packed__)); | |
void encode(const char *msg, const size_t siz, struct encoded *encoded_msg) { | |
int j; | |
for (j = 0; j < siz; j++) { | |
const unsigned int encoded_char = encoding[msg[j]]; | |
struct encoded _stack = { | |
.character = encoded_char, | |
}; | |
memcpy(&encoded_msg[j], &_stack, sizeof(struct encoded)); | |
} | |
} | |
char *decode(const struct encoded *encoded_msg) { | |
return NULL; | |
} | |
int main(const int argc, char *argv[]) { | |
int i; | |
for (i = 0; i < (sizeof(tests)/sizeof(tests[0])); i++) { | |
const char *current_test = tests[i]; | |
const size_t test_siz = strlen(current_test); | |
struct encoded encoded_msg[test_siz]; | |
encode(current_test, test_siz, encoded_msg); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment