/* encode_stub.c - Don Yang (uguu.org) 08/25/12 */ #include typedef unsigned int word; static word result[256], result_count; static word mm[256], aa, bb, cc; static word i, j, w, x, y; #if 1 static word seed[] = { 86, 0 }; static char data[] = "0123456789\n\0"; #else static word seed[] = { 0 }; static char data[] = "The chaos that always crawls up to you with a smile, Nyarlathotep\n"; #endif static word Isaac() { if( !result_count-- ) { bb += ++cc; for(i = 0; i < 256; bb = result[i++] = mm[(y >> 10) & 255] + x) { aa ^= (i & 1) ? aa >> ((i & 2) ? 16 : 6) : aa << ((i & 2) ? 2 : 13); x = mm[i]; y = mm[i] = mm[(x >> 2) & 255] + (aa += mm[(i + 128) & 255]) + bb; } result_count = 255; } return result[result_count]; } static void Init() { for(j = 0; j < 256; mm[j++] = 0); for(j = 0; j < sizeof(seed) / sizeof(word); j++) mm[j & 255] ^= seed[j]; for(aa = bb = cc = result_count = j = 0; j < 1 << 24; j++) Isaac(); j = w = 0; } static void EncodeBlock(word block) { char buffer[5]; word i, x; block ^= Isaac(); for(i = 5; i != 0;) { x = block % 85; block /= 85; buffer[--i] = (x <= 31 ? x + 95 : x + 6); } fwrite(buffer, 5, 1, stdout); } static void Encode() { char *input; word block, block_size; /* Encode input 4 bytes at a time */ block = block_size = 0; for(input = data; *input != '\0'; input++) { block |= ((*input) & 0xff) << (8 * block_size); block_size++; if( block_size == 4 ) { EncodeBlock(block); block = block_size = 0; } } /* Encode final block */ if( block_size != 0 ) { EncodeBlock(block); putchar(block_size == 1 ? '!' : block_size == 2 ? '%' : '$'); } else { putchar('#'); } putchar('\n'); } int main() { Init(); Encode(); return 0; }