home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / XMK.ZIP / XMK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-25  |  1.8 KB  |  81 lines

  1. #include <io.h>
  2. #include <sys\stat.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <string.h>
  7. #include <fcntl.h>
  8.  
  9. #define KEYSIZE   0x65
  10. #define FILESIZE  0x400
  11.  
  12. long Change( char *pBuf )
  13. {
  14.     static char bKey[] = {
  15.             0x08, 0x0e, 0x1f, 0x09, 0x1b, 0x0f, 0x08, 0x0f, 0x09
  16.             };
  17.     int    i, j, t;
  18.     long    lCRC;
  19.  
  20.     j = 1;
  21.     lCRC = 0;
  22.     for( i = 0; i < KEYSIZE; i ++ ){
  23.         t = bKey[ j ] ^ ( pBuf[ i ] ^ j );
  24.         pBuf[ i ] = t;
  25.         lCRC += t << j;
  26.         if( j++ == bKey[ 0 ] ) j = 1;
  27.     }
  28.     return lCRC;
  29. }
  30.  
  31. void main( void )
  32. {
  33.     int    nZone, nRegion, nNode, nPoint;
  34.     int    nHandle, t;
  35.     char    bName[ 64 ], *pBuf;
  36.  
  37.     pBuf = ( char * ) malloc( FILESIZE );
  38.  
  39.     printf( "\nXMK --- XMail 1.00 Key file gen..." );
  40.  
  41.     printf( "\nEnter you Zone: " );
  42.     pBuf[ 0 ] = 6;
  43.     nZone = atoi( cgets( pBuf ) );
  44.  
  45.     printf( "\nEnter you Region: " );
  46.     pBuf[ 0 ] = 6;
  47.     nRegion = atoi( cgets( pBuf ) );
  48.  
  49.     printf( "\nEnter you Node: " );
  50.     pBuf[ 0 ] = 6;
  51.     nNode = atoi( cgets( pBuf ) );
  52.  
  53.     printf( "\nEnter you Point: " );
  54.     pBuf[ 0 ] = 6;
  55.     nPoint = atoi( cgets( pBuf ) );
  56.  
  57.     printf( "\nEnter you Name: " );
  58.     pBuf[ 0 ] = 62;
  59.     cgets( pBuf );
  60.     strcpy( bName, &pBuf[ 1 ] );
  61.  
  62.     memset( pBuf, 0, FILESIZE );
  63.     *( ( int * ) &pBuf[ 0x28c ] ) = nZone;
  64.     *( ( int * ) &pBuf[ 0x28e ] ) = nRegion;
  65.     *( ( int * ) &pBuf[ 0x290 ] ) = nNode;
  66.     *( ( int * ) &pBuf[ 0x292 ] ) = nPoint;
  67.     pBuf[ 0x294 ] = 6;    // Flag
  68.     pBuf[ 0x2e9 ] = 100;    // Version Flag
  69.     pBuf[ 0x2ef ] = 0x10;    // Pro. Flag
  70.     strcpy( &pBuf[ 0x2a9 ], bName );
  71.  
  72.     Change( &pBuf[ 0x28b ] );
  73.     *( ( long * ) &pBuf[ 0x2f1 ] ) = Change( &pBuf[ 0x28b ] );
  74.     Change( &pBuf[ 0x28b ] );
  75.  
  76.     nHandle = open( "XMAIL.KEY", O_TRUNC | O_CREAT | O_WRONLY | O_BINARY );
  77.     write( nHandle, pBuf, FILESIZE );
  78.     close( nHandle );
  79.     free( pBuf );
  80. }
  81.