home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Quantico / km / bbirdrk.c.txt < prev    next >
Encoding:
Text File  |  2000-05-25  |  1.7 KB  |  100 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define NLETS    12
  5. int nlet[NLETS] = {1, 1, 1, 1, 2, 3, 4, 5, 7, 0xc, 0xc, 0x33};
  6.  
  7. char sumdigs(char* str)
  8. {
  9.     char buf[20];
  10.  
  11.     int i = 0, n = 0;
  12.  
  13.     while (str[i] != '\0')
  14.         n += str[i++] - '0';
  15.  
  16.     if (n > 9) {
  17.         sprintf(buf, "%d", n);
  18.         return sumdigs(buf);
  19.     } else
  20.         return n + '0';
  21. }
  22.  
  23. void makecode(char* name, char* comp, char* regcode)
  24. {
  25.     char nmix[200];
  26.     char rc[20];
  27.     char buf[300];
  28.     int ln, lc;
  29.     int i, in, ic;
  30.  
  31.     strupr(name);
  32.     strupr(comp);
  33.     ln = strlen(name);
  34.     lc = strlen(comp);
  35.  
  36.     ic = (lc & 0xfffe) - 1;
  37.     in = 0;
  38.     i = 0;
  39.     while (ic > 0 || in < ln) {
  40.         if (ic > 0) {
  41.             nmix[i] = comp[ic];
  42.             ic -= 2;
  43.             i++;
  44.         }
  45.         if (in < ln) {
  46.             nmix[i] = name[in];
  47.             in += 2;
  48.             i++;
  49.         }
  50.     }
  51.     ic = 0;
  52.     in = (ln & 0xfffe) - 1;
  53.     while (ic < lc || in > 0) {
  54.         if (in > 0) {
  55.             nmix[i] = name[in];
  56.             in -= 2;
  57.             i++;
  58.         }
  59.         if (ic < lc) {
  60.             nmix[i] = comp[ic];
  61.             ic += 2;
  62.             i++;
  63.         }
  64.     }
  65.     for (i; i < 100; i++)
  66.         nmix[i] = ' ';
  67.     nmix[100] = '\0';
  68.  
  69.     ic = 0;
  70.     for (i=0; i < NLETS; i++) {
  71.         for (in=0; in < nlet[i]; in++, ic++)
  72.             sprintf(buf + in*2, "%d", nmix[ic]);
  73.         rc[i] = sumdigs(buf);
  74.     }
  75.     rc[i] = '\0';
  76.     rc[i] = sumdigs(rc);
  77.     strncpy(regcode, rc, 4);
  78.     regcode[4] = '-';
  79.     strncpy(regcode+5, rc+4, 4);
  80.     regcode[9] = '-';
  81.     strncpy(regcode+10, rc+8, 5);
  82.     regcode[15] = '\0';
  83. }
  84.  
  85. void main()
  86. {
  87.     char name[200], comp[200], regcode[20];
  88.  
  89.     printf("BowerBird v1.01 Registration Code generator (fOSSiL 1998)\n\n");
  90.     printf("Name     : ");
  91.     gets(name);
  92.     printf("Company  : ");
  93.     gets(comp);
  94.     if (strlen(name) + strlen(comp) < 8) {
  95.         printf("\nOops! Name and Company together have to be at least 8 chars\n");
  96.         exit(1);
  97.     }
  98.     makecode(name, comp, regcode);
  99.     printf("Reg Code : %s\n", regcode);
  100. }