/* shift_constants.c - Don Yang (uguu.org) Find appropriate transformation constants to remap undesirable characters in string. 2014-10-16 */ #include #include int main() { int mul1, mul2, shift, boundary, c, target, all_good; int translation[256]; char text[] = "('A`)/*#:\nTimeHecateIIGlock18CjammedYOUWIN!Game over."; for(mul1 = 1; mul1 < 256; mul1++) { for(mul2 = 1; mul2 < 256; mul2++) { if( mul1 == mul2 ) continue; for(shift = 0; shift < 256; shift++) { for(boundary = 33; boundary < 127; boundary++) { /* Build reverse map */ memset(translation, 0, sizeof(translation)); for(c = 33; c < 127; c++) { if( c == '\"' || c == '\\' ) continue; target = (c * (c < boundary ? mul1 : mul2) + shift) % 256; translation[target] = c; } /* Check map validity */ all_good = 1; for(c = 0; text[c] != '\0'; c++) { if( translation[(int)(text[c])] == 0 ) { all_good = 0; break; } } if( all_good != 0 ) { printf("(chr * (chr < %d ? %d : %d) + %d) & 0xff\n", boundary, mul1, mul2, shift); } } } } } return 0; }