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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define CODESIZE    30
  6.  
  7. char lctab[]    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
  8. char codekey[CODESIZE + 1]    = "DHCJWKWA55DE N7XL4JEWLKM079AQ5";
  9. char refcode[CODESIZE + 1]    = "XT5VIRXBSIAY2N4DPHCAJSZUHMPTQ7";
  10. char cypher[CODESIZE + 1]    = "007441IBMCD210000ALE53967INT61";
  11. char liccode[CODESIZE + 1]    = "DHCJWKssssssssssL4JlllKMdccc__";
  12.  
  13.  
  14. int chartonum(char c)
  15. {
  16.     int i;
  17.     
  18.     for (i=0; lctab[i] != '\0'; i++)
  19.         if (lctab[i] == c)
  20.             return i;
  21.  
  22.     return -1;
  23. }
  24.  
  25. char numtochar(int i)
  26. {
  27.     return lctab[i];
  28. }
  29.  
  30. int procnum(int val)
  31. {
  32.     val = val % (int)(sizeof(lctab) - 1);
  33.     if (val < 0)
  34.         val += sizeof(lctab) - 1;
  35.     return val;
  36. }
  37.  
  38. void sumcodes(char* ca, char* cb, char* cr)
  39. {
  40.     int i;
  41.  
  42.     for (i=0; i<CODESIZE; i++)
  43.         cr[i] = numtochar(procnum(chartonum(ca[i]) + chartonum(cb[i])));
  44. }
  45.  
  46. void subcodes(char* ca, char* cb, char* cr)
  47. {
  48.     int i;
  49.  
  50.     for (i=0; i<CODESIZE; i++)
  51.         cr[i] = numtochar(procnum(chartonum(ca[i]) - chartonum(cb[i])));
  52. }
  53.  
  54. void printcode(char* code)
  55. {
  56.     int i;
  57.  
  58.     for (i=0; i<CODESIZE; i++) {
  59.         if (i % 5 == 0 && i)
  60.             printf("-");
  61.         printf("%c", code[i]);
  62.     }
  63. }
  64.  
  65. int stripcode(char* sc, char* dc)
  66. {
  67.     int i1=0, i2=0, cc=0, i, dash=0;
  68.     char c;
  69.  
  70.     _strupr(sc);
  71.     while (sc[i1]) {
  72.         c = sc[i1];
  73.         if (c == '-') {
  74.             for (i=cc; i<5; i++)
  75.                 dc[i2++] = ' ';
  76.             cc = 0;
  77.             dash++;
  78.         } else if (cc > 4)
  79.             return 0;
  80.         else {
  81.             dc[i2++] = c;
  82.             cc++;
  83.         }
  84.         i1++;
  85.     }
  86.     for (i=cc; i<5; i++)
  87.         dc[i2++] = ' ';
  88.  
  89.     return dash == 5;
  90. }
  91.  
  92. void checksum(char* code)
  93. {
  94.     int i, len, val=0;
  95.     char buf[10];
  96.  
  97.     len = strlen(code) - 2;
  98.     for (i=0; i < len; i++)
  99.         val += code[i];
  100.     _itoa(val, buf, 10);
  101.     strncpy(code + len, buf + strlen(buf) - 2, 2);
  102. }
  103.  
  104. int main()
  105. {
  106.     char buf[100];
  107.     
  108.     printf("Active Media Eclipse 2.1 License Key Generator\n");
  109.  
  110.     printf("Enter the Activation Reference Code (exactly, with dashes and spaces)\n>");
  111.     if (scanf("%35[^\n]", buf) != 1) {
  112.         printf("Unexpected error\n");
  113.         return 1;
  114.     }
  115.     if (!stripcode(buf, refcode)) {
  116.         printf("Invalid reference code\n");
  117.         return 1;
  118.     }
  119.     //printf("refcode : %s\n", refcode);
  120.     sumcodes(codekey, refcode, cypher);
  121.     //printf("cypher : %s\n", cypher);
  122.     strncpy(liccode + 6, cypher, 5);
  123.     strncpy(liccode + 11, cypher + 20, 5);
  124.     strncpy(liccode + 19, cypher + 9, 3);
  125.     strncpy(liccode + 25, cypher + 6, 3);
  126.     liccode[24] = cypher[5];
  127.     checksum(liccode);
  128.     //printf("liccode : %s\n", liccode);
  129.     sumcodes(liccode, refcode, liccode);
  130.     subcodes(liccode, cypher, liccode);
  131.     printf("\nLicense Code : ");
  132.     printcode(liccode);
  133.     printf("\n");
  134.     printf("\nEnter the above code including any spaces into your AME registration dialog\n");
  135.  
  136.     return 0;
  137. }