int32_t tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k) { const uint32_t rconst[11] = { 0x00000000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1b000000, 0x36000000 }; uint32_t i; uint32_t t; if (s == (TCAesKeySched_t) 0) { return TC_FAIL; } else if (k == (const uint8_t *) 0) { return TC_FAIL; } for (i = 0; i < Nk; ++i) { s->words[i] = (k[Nb*i]<<24) | (k[Nb*i+1]<<16) | (k[Nb*i+2]<<8) | (k[Nb*i+3]); } for (; i < (Nb*(Nr+1)); ++i) { t = s->words[i-1]; if ((i % Nk) == 0) { t = subword(rotword(t)) ^ rconst[i/Nk]; } s->words[i] = s->words[i-Nk] ^ t; } return TC_SUCCESS; }
bool have_suffix(const string& word, const string& suffix) { string::size_type suflen = suffix.length(); string::size_type wdlen = word.length(); if(suflen > wdlen) { return false; } int offset = wdlen-suflen; string subword(word.begin() + offset, word.end()); return (subword == suffix) ; }
void key_expansion(const bw4 * key,word_t * w) { bw temp; int i,j; for(i=0;i<4;i++) { w[i]=key->w[i]; } for(i=4;i<44;i++) { temp.w=w[i-1]; if(i%4==0) { temp.w=ROTATE_RIGHT(temp.w,32,8);//this for little Endian (bigEndian:rotate right 24bit) subword(temp,sbox); temp.w^=RC[i/4-1]; } w[i]=w[i-4]^temp.w; } }
int main(int argc, char** argv) { DIR *dp; struct dirent *ep; int result; clock_t begin, end; double time_spent; if(argc<=2) { printf("This program searches all unsolved simple families\n"); printf("for prime candidates between exponents n and m,\n"); printf("given on the command-line\n"); return 0; } mpz_t p; mpz_init(p); for(int num=atoi(argv[1]); num<=atoi(argv[2]); num++) { begin = clock(); dp = opendir("./data"); int count=0; if(dp != NULL) { while(ep = readdir(dp)) { char filename[100]; char infilename[100]; char outfilename[100]; strcpy(filename, ep->d_name); filename[8] = '\0'; if(strcmp(filename, "unsolved")==0) { strcpy(strchr(filename+9, '.'), "\0"); int n = atoi(filename+9); sprintf(infilename, "data/%s", ep->d_name); FILE* in = fopen(infilename, "r"); sprintf(outfilename, "data/tmp-%s", ep->d_name); FILE* out = fopen(outfilename, "w"); char line[100]; char start[100]; char middle; char end[100]; char candidate[MAXSTRING]; while(fgets(line, 100, in)!=NULL) { int l = (int)(strchr(line, '*')-line); middle = line[l-1]; //printf("%s", line); line[strlen(line)-1] = '\0'; line[l-1] = '\0'; strcpy(start, line); strcpy(end, line+l+1); //printf("base: %d start: %s middle: %c end: %s\n", n, start, middle, end); strcpy(candidate, start); for(int j=0; j<num; j++) sprintf(candidate, "%s%c", candidate, middle); strcat(candidate, end); //printf("candidate: %s\n", candidate); char kernelfilename[100]; sprintf(kernelfilename, "data/minimal.%d.txt", n); FILE* kernel = fopen(kernelfilename, "r"); char prime[MAXSTRING]; int hassubword = 0; //printf("Checking %s%c*%s (base %d)...\n", start, middle, end, n); while(fgets(prime, MAXSTRING, kernel)!=NULL) { prime[strlen(prime)-1] = '\0'; int k; if(subword(prime, start, middle, end, &k)==1) { if(k<=num) { hassubword = 1; break; } } } fclose(kernel); if(hassubword) { //printf("%s%c^(%d)%s (base %d) has a kernel subword %s\n", start, middle, num, end, n, prime); continue; } mpz_set_str(p, candidate, n); result = mpz_probab_prime_p(p, 25); if(result>0) { //gmp_printf("%s%c^(%d)%s (base %d) (%Zd) probably prime\n", start, middle, num, end, n, p); printf("%s%c^(%d)%s (base %d) probably prime\n", start, middle, num, end, n); FILE* append = fopen(kernelfilename, "a"); fprintf(append, "%s\n", candidate); fclose(append); } else { fprintf(out, "%s%c*%s\n", start, middle, end); count++; } } fclose(out); fclose(in); remove(infilename); rename(outfilename, infilename); } } (void)closedir(dp); } else perror("Couldn't open the directory"); printf("FINISHED LEVEL %d, COUNT REMAINING %d, TIME %f\n", num, count, (double)(clock()-begin)/CLOCKS_PER_SEC); } mpz_clear(p); return 0; }