/*** Verifica se a chave de ativacao bate com o numero de serie dado Retorna: TRUE se bateu OK FALSE se chave e num. serie nao batem. ***/ BOOL ValidKey( char *szSerial, char *szActKey ) { char cripserie[MAXSIZESERIAL+1]; int size_serie; int size_key; size_serie = strlen( szSerial ); size_key = strlen( szActKey ); if( size_serie > MAXSIZESERIAL || size_key > size_serie ) { // Se tamanho do num. serie nao OK -> ERRO return( FALSE ); } if( size_key < 3 ){ // Se tamanho da chave menor que 3 nao pode return( FALSE ); } strcpy( cripserie, szSerial ); crypt_key( cripserie, cripserie + size_serie ); // Pegamos apenas os ultimos caracteres da chave // para fins de comparacao if( strcmp( szActKey, cripserie + size_serie - size_key ) == 0 ){ /* a chave de ativacao fornecida bate com a do numero * de serie fornecido. */ return( TRUE ); } return( FALSE ); }
int crypt_file( char *source, char *dest ) { int c; FILE *infile; FILE *outfile; /* Make sure we have a key string */ while (!key_defined) crypt_key( KEY_IMMEDIATE, "?" ); /* Do any processing of the key string here */ /* Open the input and output files */ if ((infile = fopen( source, "rb" )) == NULL) { fprintf( stderr, "Can not open %s for read.\n", source); return 1; } if ((outfile = fopen( dest, "wb" )) == NULL) { fprintf( stderr, "Can not open %s for write.\n", dest); fclose( infile ); return 1; } /* Process the input to the output */ while ((c = fgetc(infile)) != EOF) { /* Put the character cipher here. */ if (fputc(c, outfile) == EOF) { fprintf(stderr, "Could not write to output file %s\n", dest); fclose( infile ); fclose( outfile ); return 1; } } /* Close the files */ fclose( infile ); fclose( outfile ); return 0; }
int crypt_file (char *source, char *dest) { int i; int count = 16; /* block size */ char buffer[16]; FILE *infile; FILE *outfile; while (!key_defined) crypt_key (KEY_IMMEDIATE, "?"); if ((infile = fopen (source, "rb")) == NULL) { fprintf (stderr, "Can not open %s for reading.\n", source); return 1; } if ((outfile = fopen (dest, "wb")) == NULL) { fprintf (stderr, "Can not open %s for writing.\n", dest); fclose (infile); return 1; } for (i = 0; i < count; i++) buffer[i] = (char) 0x20; /* text files padded with spaces */ while (fread (buffer, sizeof (char), count, infile)) { lucifer (buffer); if (count != fwrite (buffer, sizeof (char), count, outfile)) { fprintf (stderr, "Could not write to %s\n", source); fclose (infile); fclose (outfile); return 1; } else { for (i = 0; i < count; i++) buffer[i] = (char) 0x20; } } fclose (infile); fclose (outfile); return 0; }
int crypt_file( char *source, char *dest ) { char *s; int c; unsigned long k; FILE *infile; FILE *outfile; while (!key_defined) crypt_key( KEY_IMMEDIATE, "?" ); set_rnd_seed( initial_seed ); if ((infile = fopen( source, "rb" )) == NULL) { fprintf( stderr, "Can not open %s for reading.\n", source); return 1; } if ((outfile = fopen( dest, "wb" )) == NULL) { fprintf( stderr, "Can not open %s for writing.\n", dest); fclose( infile ); return 1; } while ((c = fgetc(infile)) != EOF) { k = (unsigned long) rnd(); c ^= (int) ( 0xffff & k ); if (fputc(c, outfile) == EOF) { fprintf(stderr, "Could not write to output file %s\n", dest); fclose( infile ); fclose( outfile ); return 1; } } fclose( infile ); fclose( outfile ); return 0; }
int crypt_file( char *source, char *dest ) { char *s; int c; int iRow; int iCol; FILE *infile; FILE *outfile; while (!key_defined) crypt_key( KEY_IMMEDIATE, "?" ); if ((infile = fopen( source, "rb" )) == NULL) { fprintf( stderr, "Can not open %s for reading.\n", source); return 1; } if ((outfile = fopen( dest, "wb" )) == NULL) { fprintf( stderr, "Can not open %s for writing.\n", dest); fclose( infile ); return 1; } if ( encrypt_or_decrypt == DECRYPTION_SELECT ) { c = rows; rows = columns; columns = c; } trans.max = rows * columns; while (trans.left=fread (trans.data, sizeof (char), trans.max, infile)) { trans.next = trans.data; while (setblock() != 0) for(iCol=0; iCol<trans.column; iCol++) for(iRow=0; iRow<trans.row ;iRow++) { c = *((trans.start)+iCol+iRow*(trans.column)); if (fputc(c, outfile) == EOF) { fprintf(stderr, "Could not write to output file %s\n", dest); fclose( infile ); fclose( outfile ); return 1; } } if(trans.left) /* if less than 3 bytes, reverse */ for(iCol=0; iCol<trans.left; iCol++) { c = *(trans.start + trans.left - 1 - iCol); if (fputc(c, outfile) == EOF) { fprintf(stderr, "Could not write to output file %s\n", dest); fclose( infile ); fclose( outfile ); return 1; } } } if ( encrypt_or_decrypt == DECRYPTION_SELECT ) { c = rows; rows = columns; columns = c; } fclose( infile ); fclose( outfile ); return 0; }
int crypt_file (char *source, char *dest) { int i; int count = 8; /* block size */ char fPath[_MAX_PATH]; char sDrive[_MAX_DRIVE]; char sDir[_MAX_DIR]; char sFname[_MAX_FNAME]; char sExt[_MAX_EXT]; char buffer[8]; char cbc[8]; char fcbc[8]; char seed[8]; char *path; FILE *infile; FILE *outfile; while (!key_defined) crypt_key (KEY_IMMEDIATE, "?"); if ((infile = fopen (source, "rb")) == NULL) { fprintf (stderr, "Can not open %s for reading.\n", source); return 1; } if ((outfile = fopen (dest, "wb")) == NULL) { fprintf (stderr, "Can not open %s for writing.\n", dest); fclose (infile); return 1; } if (encrypt_or_decrypt == ENCRYPTION_SELECT) strcpy(fPath, source); else strcpy(fPath, dest); path = _fullpath(NULL, fPath, 0); _splitpath( path, sDrive, sDir, sFname, sExt ); free(path); for (i = 0; i < 8; i++) { buffer[i] = (char) 0x20; /* text files padded with spaces */ cbc[i] = fcbc[i] = seed[i] = '\0'; /* constant initialization vector */ } for (i=0; i < 8; i++) /* copy up to 8 letters from simple file name */ { if (sFname[i] == '\0') break; cbc[i] = fcbc[i] = toupper(sFname[i]); } while (count = fread (buffer, sizeof (char), count, infile)) { if (encrypt_or_decrypt == ENCRYPTION_SELECT) { for (i=0; i<8; i++) buffer[i] ^= cbc[i]; if (count == 8) ideaCfbEncrypt(&cfb, buffer, buffer, 8); else { ideaCfbEncrypt(&cfb, cbc, seed, 8); for (i=0; i<8; i++) buffer[i] ^= seed[i]; } for (i=0; i<8; i++) cbc[i] = buffer[i]; } else { for (i=0; i<8; i++) cbc[i] = buffer[i]; if (count == 8) ideaCfbDecrypt(&cfb, buffer, buffer, 8); else { ideaCfbEncrypt(&cfb, fcbc, seed, 8); for (i=0; i<8; i++) buffer[i] ^= seed[i]; } for (i=0; i<8; i++) { buffer[i] ^= fcbc[i]; fcbc[i] = cbc[i]; } } if (count != fwrite (buffer, sizeof (char), count, outfile)) { fprintf (stderr, "Could not write to %s\n", source); fclose (infile); fclose (outfile); return 1; } else { for (i = 0; i < 8; i++) buffer[i] = (char) 0x20; } } for (i=0; i<8; i++) cbc[i] = fcbc[i] = seed[i] = '\0'; fclose (infile); fclose (outfile); return 0; }