#include #include #include #include #include #include #include "uici.h" #define decprec 78 #define b1prec 127 #define b2prec 256 /* b2prec should be b1prec*2+2 */ #define server "bach.dynet.com" #define readport 7996 #define writeport 7995 #define BLKSIZE 1024 /* main() */ int main() { /* Variables for computation */ long kcount; int i, j, jcount, k, l, pcount, pflag, subtr1flag, finished; int d[decprec]; int b1[b1prec]; int b2[b2prec]; int bn[b2prec][decprec]; int lp1[b2prec]; FILE *wsf; /* Variables for networking */ u_port_t portnum; int commfd; ssize_t bytesread; int bytes_copied; char buf[BLKSIZE]; char results[BLKSIZE] = ""; int ri; /* results array index */ char unithalf[70]; char starthalf[70]; char current[70]; char authcode[9]; char str[157], tmpstr[9]; while (1) { /* Main Loop */ /* Init some variables */ ri=0; kcount=0; jcount=0; pcount=0; pflag=1; subtr1flag=0; for (i=0; i<70; i++) { starthalf[i]=0; unithalf[i]=0; current[i]=0; } for (i=0; i<9; i++) { authcode[i]=0; tmpstr[i]=0; } for (i=0; i-1; i-=1) { if (starthalf[i] == '1') { b1[j]=1; } else { b1[j]=0; } j++; } l=j-1; /* Strip leading zeros if any exist */ j=l; while ((j>-1) && (b1[j]==0)) { l-=1; j-=1; } if (subtr1flag) { /* Now subtract 1 from the binary half to counter the first increment */ /* This is because in the case of getting the starthalf from the */ /* server, the starthalf has not been looked at yet. But when getting */ /* the starthalf from the .worksave file, the last half has already */ /* been looked at so we don't need to look at it again (it would also */ /* throw off our count). */ i=0; while ((b1[i]==0) && (i < b1prec)) { i++; } b1[i]=0; if (i==l) { l-=1; } if (i != b1prec) { for (j=0; jl) { l++; } for (j=0; j-1; i-=1) { b2[j]=b1[i]; j++; } for (i=0; i<=l; i++) { b2[j]=b1[i]; j++; } /* j is now the length+1 of b2. (b2[0..j-1]) */ /* Convert b2 to decimal d */ for (i=0; i-1; j-=1) { printf("%d", b2[j]); results[ri] = b2[j] + 48; ri++; } i-=1; printf(" "); results[ri] = ' '; ri++; for (j=i; j>-1; j-=1) { printf("%d", d[j]); results[ri] = d[j] + 48; ri++; } printf("\n"); results[ri] = '\n'; ri++; } /* Create b2 binary palindrome #2. */ j=0; for (i=l; i>-1; i-=1) { b2[j]=b1[i]; j++; } b2[j]=0; j++; for (i=0; i<=l; i++) { b2[j]=b1[i]; j++; } /* j is now the length+1 of b2. (b2[0..j-1]) */ /* Convert b2 to decimal d */ for (i=0; i-1; j-=1) { printf("%d", b2[j]); results[ri] = b2[j] + 48; ri++; } i-=1; printf(" "); results[ri] = ' '; ri++; for (j=i; j>-1; j-=1) { printf("%d", d[j]); results[ri] = d[j] + 48; ri++; } printf("\n"); results[ri] = '\n'; ri++; } /* Create b2 binary palindrome #3. */ j=0; for (i=l; i>-1; i-=1) { b2[j]=b1[i]; j++; } b2[j]=1; j++; for (i=0; i<=l; i++) { b2[j]=b1[i]; j++; } /* j is now the length+1 of b2. (b2[0..j-1]) */ /* Convert b2 to decimal d */ for (i=0; i-1; j-=1) { printf("%d", b2[j]); results[ri] = b2[j] + 48; ri++; } i-=1; printf(" "); results[ri] = ' '; ri++; for (j=i; j>-1; j-=1) { printf("%d", d[j]); results[ri] = d[j] + 48; ri++; } printf("\n"); results[ri] = '\n'; ri++; } kcount++; if (kcount==8388608) { /* 8,388,608 loops to save current binary half */ kcount=0; jcount++; pcount++; /* Save current binary half to file */ if ((wsf = fopen(".worksave", "w")) == NULL) { fprintf(stderr, "Cannot open .worksave file.\n");; exit(1); } /* Set current[] to the string of the current binary half */ i=0; for (j=l; j>-1; j-=1) { current[i]=b1[j]+48; i++; } current[i]=0; /* fprintf all the necessary info to the file */ fprintf(wsf, "%s %s %s %d %d\n", unithalf, authcode, current, jcount, pcount); fclose(wsf); if (pcount==4) { /* 33,554,432 loops to print current binary half */ /* Print out current binary half */ printf("%s\n", current); pcount++; } if (jcount==128) { /* 1,073,741,824 loops to a unit */ jcount=0; /* Now set buf to the data to upload */ i=0; while (i