#include #include //#define PRINTABLE_HASH_FF16 /* Find a printable 4-character key, remembering (see Photoshop API guide): - All IDs starting with an uppercase letter are reserved by Adobe. - All IDs that are all uppercase are reserved by Apple. - All IDs that are all lowercase are reserved by Apple. - This leaves all IDs that begin with a lowercase letter and have at least one uppercase letter for you and other plug-in developers. */ unsigned long printablehash(unsigned long hash) { #ifdef PRINTABLE_HASH_FF16 // FilterFoundry version 1.6 hashing by Toby Thain // Only accepts upper case at the last character // 0 = 'a A' // 6100899 = 'z~~Z' unsigned long key = 'a' + (hash % 26); hash /= 26; // first lower case key = (key << 8) | (' ' + (hash % 95)); hash /= 95; // any printable key = (key << 8) | (' ' + (hash % 95)); hash /= 95; // any printable return (key << 8) | ('A' + (hash % 26)); // last upper case #else // FilterFoundry version 1.7 hashing by Daniel Marschall // Accepts upper case at character 2, 3 or 4 // Spaces are only set the right as padding to make a code shorter // 0 = 'aA ' // 13530139 = 'zZZZ' // The key-space is ~2.22 times larger long lowlim; long uplim; int upperCaseInfo; int length; int lastThreeCharInfo; int firstChar; unsigned long key; int found; int i,j,k; uplim = 0; for (k=1; k<4; k++) { int mask; if (k == 1) mask = 0b1; if (k == 2) mask = 0b11; if (k == 3) mask = 0b111; for (i=1; i<=mask; i++) { // 'k' characters long test = 1; for (j=0; j= lowlim) && (lastThreeCharInfo < uplim)) { lastThreeCharInfo -= lowlim; found = 1; length = k; upperCaseInfo = i; break; } lowlim = uplim; } } key = ('a' + firstChar) << 24; // first char is lower-case for (i=0; i= 'A') res += 26; lastThreeCharInfo /= (94-26); } else { res = 'A' + (lastThreeCharInfo % 26); lastThreeCharInfo /= 26; } key |= res << (8*(i+(4-length-1))); // 2nd, 3rd, 4th char are either upper-case or any printable char } if (length == 1) { key &= 0xFFFF0000; key |= ' ' << 8; key |= ' '; } if (length == 2) { key &= 0xFFFFFF00; key |= ' '; } return key; #endif } int main() { unsigned long x; for (long i=0; i<1; i++) { x = printablehash(i); printf("%i = '%c%c%c%c'\n", (int)i, (int)((x>>24) & 0xFF), (int)((x>>16) & 0xFF), (int)((x>>8) & 0xFF), (int)((x>>0) & 0xFF)); } //return 0; for (long i=0; 1; i++) { x = printablehash(i); if (((x>>24) & 0xFF) == 'z') if (((x>>16) & 0xFF) == 'Z') if (((x>>8) & 0xFF) == 'Z') if (((x>>0) & 0xFF) == 'Z') { printf("bingo 1.7! %i\n", i); printf("%i = '%c%c%c%c'\n", (int)i, (int)((x>>24) & 0xFF), (int)((x>>16) & 0xFF), (int)((x>>8) & 0xFF), (int)((x>>0) & 0xFF)); i++; x = printablehash(i); printf("%i = '%c%c%c%c'\n", (int)i, (int)((x>>24) & 0xFF), (int)((x>>16) & 0xFF), (int)((x>>8) & 0xFF), (int)((x>>0) & 0xFF)); break; } } return 0; }