Código: Seleccionar todo
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* @name: ReverseROT1 Encryption example
@programmer: The Swash
@date: 24 december 2010
*/
char * Crypt(char * str, int size);
char * Decrypt(char * str, int size);
char * StrReverse(char * str, int size);
main(){
FILE * archivo;
int isize,bytes;
char * buffer;
archivo = fopen("C:\Replace.exe","rb");
if (archivo != NULL){
fseek(archivo,0, SEEK_END);
isize = ftell(archivo);
rewind(archivo);
buffer = (char *) malloc(isize * sizeof(char));
bytes = fread(buffer,1,isize,archivo);
if (bytes = isize){
printf("Archivo leido correctamente \n");
}
else{
printf("Error al leer el archivo \n");
}
fclose(archivo);
}
else{
printf("Error al abrir el archivo\n");
};
archivo = fopen("C:\crypted.exe","wb");
if (archivo != NULL){
fwrite(StrReverse(Crypt(buffer,isize),isize),1,isize,archivo);
fclose(archivo);
printf("Archivo encryptado escrito correctamente \n");
}
else{
printf("Error al abrir el archivo \n");
}
archivo = fopen("C:\DCrypted.exe","wb");
if (archivo != NULL){
fwrite(StrReverse(Decrypt(StrReverse(Crypt(buffer,isize),isize),isize),isize),1,isize,archivo);
fclose(archivo);
printf("Archivo desencryptado correctamente");
}
else{
printf("Error al abrir el archivo \n");
}
free(buffer);
getchar();
}
char * StrReverse(char * string, int size){
int j , n=0;
char * temporal;
temporal = (char *) malloc(size);
for (j = size-1 ; j >= 0 ; j--) {
temporal[n] = (char) (int) string[j];
n++;
}
return temporal;
}
char * Crypt(char * str, int size){
int i;
char * temp;
temp = (char *) malloc(size);
for (i = 0 ; i < size ; i++){
if ((int) str[i] != 255){
temp[i] = (char) (int) str[i] + 1;
}
else {
temp[i] = (char) 0;
}
}
return temp;
}
char * Decrypt(char * str, int size){
int i;
char * temp;
temp = (char *) malloc(size);
for (i = 0 ; i < size ; i++){
if ((int) str[i] != 0){
temp[i] = (char) (int) str[i] - 1;
}
else {
temp[i] = (char) 255;
}
}
return temp;
}
PD: Linkgl te dedico este trabajo y te agradezco toda la ayuda brindada.
Saludos.