home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / sci / crypt / 5751 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.5 KB  |  76 lines

  1. Newsgroups: sci.crypt
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!kocherp
  3. From: kocherp@leland.Stanford.EDU (Paul Carl Kocher)
  4. Subject: GWBASIC encryption broken (code included)
  5. Message-ID: <1992Dec16.225055.27830@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (USENET News System)
  7. Organization: DSG, Stanford University, CA 94305, USA
  8. Date: Wed, 16 Dec 92 22:50:55 GMT
  9. Lines: 65
  10.  
  11. I don't remember who first posted about the GWBASIC encryption about
  12. a week ago, so I'm posting this for all who are interested.
  13.  
  14. It turns out that the GWBASIC encryption algorithm is basically what
  15. I thought it was -- just a couple ADD/SUB/XORs using (as I had guessed
  16. from the 143-byte periodicity) an 11-byte key and a 13-byte key.
  17.  
  18. The code was written quickly -- it's finals week and I have an exam
  19. tomorrow ;-) and worked on my test file but has not been checked
  20. for bugs.  Let me know if you find any problems with it.
  21.  
  22. -- Paul
  23.  
  24. ________Paul C. Kocher, Box 13554, Stanford, CA 94309, 415/497-6589_________
  25. kocherp@leland.stanford.edu (preferred), root@kocher.stanford.edu.  Contract
  26. programming work sought (PC assembly, security, etc) -- write/call for info.
  27.  
  28.  
  29. BASCRACK.C---------------------------------------------------------------
  30.  
  31. #include <stdio.h>
  32.  
  33. int main(int argc, char **argv) {
  34.  
  35.      unsigned char key1[13]={       
  36.         0xA9,0x84,0x8D,0xCD,0x75,0x83,0x43,0x63,0x24,0x83,0x19,0xF7,0x9A};
  37.      unsigned char key2[11]={ 
  38.         0x1E,0x1D,0xC4,0x77,0x26,0x97,0xE0,0x74,0x59,0x88,0x7C};
  39.      int nextbyte, index;
  40.      unsigned char c;
  41.      FILE *infile, *outfile;
  42.  
  43.      if (argc != 3) {
  44.         printf("Utility to decrypt GWBASIC/BASICA files saved with \",p\"\n\n"
  45.                "Copyright 1992 by Paul C. Kocher.  All rights reserved.\n\n"
  46.                "Usage: BASCRACK encrypted.bas outfile.bas\n");
  47.         exit(1);
  48.      }
  49.  
  50.      if ((infile=fopen(argv[1],"rb"))==NULL ||
  51.         (outfile=fopen(argv[2],"wb"))==NULL) {
  52.         printf("Error opening file.\n");
  53.         exit(1);
  54.      }
  55.  
  56.      if (fgetc(infile) == 0xFE) {
  57.         fputc(0xFF, outfile);
  58.      } else {
  59.         printf("Not an encrypted BASIC file\n");
  60.         exit(1);
  61.      } 
  62.  
  63.      index = 0;
  64.      nextbyte=fgetc(infile);
  65.      while (c=nextbyte, (nextbyte=fgetc(infile)) != EOF) {
  66.         c -= 11 - (index % 11);
  67.         c ^= key1[ index % 13 ];
  68.         c ^= key2[ index % 11 ];
  69.         c += 13 - (index % 13);
  70.         fputc(c, outfile);
  71.         index = (index+1) % (13*11);
  72.      }
  73.      fputc(c, outfile); /* Don't decrypt the EOF character */
  74.      return 0;
  75. }
  76.