Dando una vuelta me encontre esto, sino vale me lo dicen y lo tiro.

Código: Seleccionar todo

//XOR Encryption

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 256

void strip_newline(char* to_strip);
void encrypt_data(FILE* input_file, FILE* output_file, char *key);

int main(int argc, char* argv[])
{
	//Check for valid number of arguments
	if (argc != 3)
	{
		printf("Invalid number of arguments. %d arguments were supplied.\n", argc);
		printf("Usage: %s inputfile outputfile\n", argv[0]); //Usage: ./xortest inputfile outputfile
		exit(0);
	}
	
	FILE* input;
	FILE* output;

	//Open input and output files
	input = fopen(argv[1], "r");
	output = fopen(argv[2], "w");
		

	//Check input file
	if (input == NULL)
	{
		printf("Input file cannot be read.\n");
		exit(0);
	}
		
	//Check output file
	if (output == NULL)
	{
		printf("Output file cannot be written to.\n");
		exit(0);
	}

	//Key strings
	char *key = malloc(MAX_SIZE);

	//Prompt for key
	printf("Passphrase: ");

	//Read in key
	fgets(key, MAX_SIZE, stdin);

	printf("Encrypting %s\n", argv[1]);

	//strip newlines
	strip_newline(key);

	//XOR data and write it to file
	encrypt_data(input, output, key);
	
	printf("Encrypted data written to %s\n", argv[2]);

	//Release memory
	free(key);

	//Close files
	fclose(input);
	fclose(output);

	return 0;

}


void encrypt_data(FILE* input_file, FILE* output_file, char* key)
{
	int key_count = 0; //Used to restart key if strlen(key) < strlen(encrypt)
	int encrypt_byte;
	
	while( (encrypt_byte = fgetc(input_file)) != EOF) //Loop through each byte of file until EOF
	{
		//XOR the data and write it to a file
		fputc(encrypt_byte ^ key[key_count], output_file);

		//Increment key_count and start over if necessary
		key_count++;
		if(key_count == strlen(key))
			key_count = 0;
	}
}

void strip_newline(char* to_strip)
{
	//remove newlines
	if (to_strip[strlen(to_strip) - 1] == '\n')
	{
		to_strip[strlen(to_strip) - 1] = '\0';
	}
}
La felicidad es una cualidad evasiva. Si la buscas, no la encuentras.
Imagen
Pues esta muy buena la funcion,la estube mirando y esta mas simple de lo que me parecia

Salu2
Blog técnico dedicado a la seguridad informática y al estudio de nuevas vulnerabilidades.
Blog: http://www.seginformatica.net
Twitter: https://twitter.com/#!/p0is0nseginf
otra manera de encriptar mediante XOR , lo hice directo al textbox del foro asique puede tener algun error por ahí

Código: Seleccionar todo

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void encriptar_xor( char* ptr , int xor )
{
      for( ; *ptr != '\0' ; ptr++ )
      {
            *ptr = *ptr ^ xor;
      }
}

int main()
{
       char* nombre = ( char * )malloc( sizeof( char ) * 30 );
       memset( nombre , 0 , sizeof( char ) * 30 );

       printf( "Ingrese el Nombre del Archivo a Encriptar : "  );
       scanf( "%s" , nombre );

       FILE* file = fopen( nombre , "rb" );
       
      if( !file ){ printf( "El Archivo no existe \n" ); system( "pause" );  return 0; }

     fseek( file , 0 , SEEK_END );
     int final = ftell( file ); 
     fseek( file , 0 , SEEK_SET );
    
     char* buffer_ = ( char* )malloc( sizeof( char ) * final );
     memset( buffer , 0 , sizeof( char ) * final )

     fread( buffer , sizeof( char ) , sizeof( char ) * final , file );
     encriptar_xor( buffer , 4 );
     
     char* nombre_enc = ( char * )malloc( sizeof( char ) * 40 );
     strcpy( nombre_enc ,  "Encrypt_" );
     strcat( nombre_enc , nombre );
     
     FILE* encr = fopen( nombre_enc , "wb" );
     fwrite( buffer , sizeof( char ) , sizeof( char ) * final , encr );

     fclose( file );
     fclose( encr );
     free( nombre );
     free( nombre_enc ); 
     
     system( "pause" );
     return 0;
}
Gracias depu ya le echo un ojo
Mi blog

www.MasaSoftware.blogspot.com

Encontraras herramientas como el Masacrypter mods Indetectables joiner

___________
Responder

Volver a “Fuentes”