/* zero_crc.c - Don Yang (uguu.org) Append C comment to program such that CRC is zero. 2015-10-02 */ #include #include static int table[256]; static const char tail[] = "*/\n"; static char pad[6]; int main() { int i, j; unsigned c, tail0, c0; /* Build CRC table */ for(i = 0; i < 256; i++) { c = i; for(j = 0; j < 8; j++) { if( (c & 1) != 0 ) c = (c >> 1) ^ 0xedb88320; else c >>= 1; } table[i] = c; } /* Compute tail value needed to be matched */ for(tail0 = 0; ++tail0 != 0;) { c = tail0; for(i = 0; tail[i] != '\0'; i++) { j = tail[i]; c = (c >> 8) ^ table[(c ^ j) & 0xff]; } if( c == ~0 ) break; } assert(tail0 == 0xa32409ab); /* Process input */ c = ~0; while( (i = getchar()) != EOF ) { putchar(i); c = (c >> 8) ^ table[(c ^ i) & 0xff]; } /* Compute fudge bytes needed */ c = (c >> 8) ^ table[(c ^ '/') & 0xff]; c = (c >> 8) ^ table[(c ^ '*') & 0xff]; for(i = 0; i < 6; i++) pad[i] = ';'; do { c0 = c; for(i = 0; i < 6; i++) c0 = (c0 >> 8) ^ table[(c0 ^ pad[i]) & 0xff]; if( c0 == tail0 ) break; for(i = 0; i < 6; i++) { pad[i]++; if( pad[i] > 'z' ) pad[i] = ';'; else break; } } while( i < 6 ); printf("/*%c%c%c%c%c%c*/\n", pad[0], pad[1], pad[2], pad[3], pad[4], pad[5]); return 0; } /*qYdUj<*/