🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.crypt
Article #2274

GWBASIC encryption broken (code included)

#2274
From: Paul Carl Kocher
Date: Wed, 16 Dec 1992 22:50
65 lines
2617 bytes
I don't remember who first posted about the GWBASIC encryption about
a week ago, so I'm posting this for all who are interested.

It turns out that the GWBASIC encryption algorithm is basically what
I thought it was -- just a couple ADD/SUB/XORs using (as I had guessed
from the 143-byte periodicity) an 11-byte key and a 13-byte key.

The code was written quickly -- it's finals week and I have an exam
tomorrow ;-) and worked on my test file but has not been checked
for bugs.  Let me know if you find any problems with it.

-- Paul

________Paul C. Kocher, Box 13554, Stanford, CA 94309, 415/497-6589_________
kocherp@leland.stanford.edu (preferred), root@kocher.stanford.edu.  Contract
programming work sought (PC assembly, security, etc) -- write/call for info.


BASCRACK.C---------------------------------------------------------------

#include <stdio.h>

int main(int argc, char **argv) {

     unsigned char key1[13]={       
        0xA9,0x84,0x8D,0xCD,0x75,0x83,0x43,0x63,0x24,0x83,0x19,0xF7,0x9A};
     unsigned char key2[11]={ 
        0x1E,0x1D,0xC4,0x77,0x26,0x97,0xE0,0x74,0x59,0x88,0x7C};
     int nextbyte, index;
     unsigned char c;
     FILE *infile, *outfile;

     if (argc != 3) {
        printf("Utility to decrypt GWBASIC/BASICA files saved with \",p\"\n\n"
               "Copyright 1992 by Paul C. Kocher.  All rights reserved.\n\n"
               "Usage: BASCRACK encrypted.bas outfile.bas\n");
        exit(1);
     }

     if ((infile=fopen(argv[1],"rb"))==NULL ||
        (outfile=fopen(argv[2],"wb"))==NULL) {
        printf("Error opening file.\n");
        exit(1);
     }

     if (fgetc(infile) == 0xFE) {
        fputc(0xFF, outfile);
     } else {
        printf("Not an encrypted BASIC file\n");
        exit(1);
     } 

     index = 0;
     nextbyte=fgetc(infile);
     while (c=nextbyte, (nextbyte=fgetc(infile)) != EOF) {
        c -= 11 - (index % 11);
        c ^= key1[ index % 13 ];
        c ^= key2[ index % 11 ];
        c += 13 - (index % 13);
        fputc(c, outfile);
        index = (index+1) % (13*11);
     }
     fputc(c, outfile); /* Don't decrypt the EOF character */
     return 0;
}
Technical Details
Message-ID: <1992Dec16.225055.27830@leland.Stanford.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!nntp.Stanford.EDU!kocherp

Show Full Headers
Complete Article Headers
Newsgroups: sci.crypt
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!nntp.Stanford.EDU!kocherp
From: kocherp@leland.Stanford.EDU (Paul Carl Kocher)
Subject: GWBASIC encryption broken (code included)
Message-ID: <1992Dec16.225055.27830@leland.Stanford.EDU>
Sender: news@leland.Stanford.EDU (USENET News System)
Organization: DSG, Stanford University, CA 94305, USA
Date: Wed, 16 Dec 92 22:50:55 GMT
Lines: 65