Programı yazan kişiye saygı açısından kodlarda değişiklik yapılmamıştır.


Kod:
 /******************************************

  *** yazan:  erenezgu@gmail.com  ***********
  *** Parola ile dosya þifreleme programý ***
  ******************************************/
#include<string.h>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
char *scan_unlimited_string(char *ptr){  
	int k=0;
	ptr=malloc(1);

	scanf("%c",&ptr[k]);
	while( ptr[k]!='\n'){
		k++;
		ptr=realloc(ptr,k+1);
		scanf("%c",&ptr[k]);
	}
	ptr[k]='\0';
	return ptr;
}

int main(int argn,char *argv[]){
	/* kullan&#253;m: passcode -e/-d  inputfile  outputfile  */
	char *password, *password_control;
	FILE *dosya,*dosya2;
	int len,i;
	unsigned char ch,ch2;
		 		 
	if(argn!=4){
		puts("\nprogram source: www.cprogramlama.com.tr.tc\n");
		puts("Usage: passcode -e/-d inputfile  outputfile");
		puts("-e : encode");
		puts("-d : decode");
		exit(1);
	}
	/************************ENCODE************************/
	if( !strcmp(argv[1],"-e")  ){
		/*&#222;ifreleme i&#254;lemi yap&#253;lacak...*/
		puts("Enter password for encoding file:");
		password=scan_unlimited_string(password);		
		puts("Enter again:");
		password_control=scan_unlimited_string(password_control);
		if( strcmp(password,password_control) ){
			puts("Different passwords!");
			exit(1);
		}
		printf("Password ok. Accessing input file \"%s\"...\n",argv[2]);
		if(! (dosya=fopen(argv[2],"r"))  ){
			printf("Can't open the input file: %s \n",argv[2]);
			exit(1);									  
		}
				
		if( ( dosya2=fopen(argv[3],"r") )  ){
			puts("This file already exists in the directory!");
			puts("Choose another output filename.");
			exit(1);									  
		}
		if(! (dosya2=fopen(argv[3],"w"))  ){
			printf("Can't open the output file: %s \n",argv[3]);
			exit(1);									  
		}
		/*All files opened */
		
		len=strlen(password);
		i=0;
		fscanf(dosya,"%c",&ch);
		while(!feof(dosya)){			
			/* 
			filetext:         text_to_be_encoded...
			password:         passwordpasswordpa...
			password index:   012345670123456701...
				password > len=8			
			*/			
			ch2=( ch+password[i] ) % 256;/*&#254;ifreleme için artt&#253;rma yap&#253;l&#253;yor*/
			fprintf(dosya2,"%c",ch2);			
			i=(i+1)%len; /* i=7 ise 0 olur i parolan&#253;n indisidir*/
			fscanf(dosya,"%c",&ch);
		}
		fclose(dosya);
		fclose(dosya2);
		puts("Encoding completed!");
	}			 
	/************************DECODE************************/	
	else if( !strcmp(argv[1],"-d") ){
		 /*&#254;ifre çözülecek*/
		 
		puts("Enter password for decoding file:");
		password=scan_unlimited_string(password);		
		
		printf("Accessing input file \"%s\"...\n",argv[2]);
		if(! (dosya=fopen(argv[2],"r"))  ){
			printf("Can't open the input file: %s \n",argv[2]);
			exit(1);									  
		}
				
		if( ( dosya2=fopen(argv[3],"r") )  ){
			puts("This file already exists in the directory!");
			puts("Choose another output filename.");
			exit(1);									  
		}
		if(! (dosya2=fopen(argv[3],"w"))  ){
			printf("Can't open the output file: %s \n",argv[3]);
			exit(1);									  
		}
		/*All files opened */
		
		len=strlen(password);
		i=0;
		fscanf(dosya,"%c",&ch);
		while(!feof(dosya)){			
			/* 
			filetext:         text_to_be_encoded...
			password:         passwordpasswordpa...
			password index:   012345670123456701...
				password > len=8			
			*/			
			ch2=(ch+256-password[i])%256;  /*&#254;ifre çözülüyor*/
			fprintf(dosya2,"%c",ch2);			
			i=(i+1)%len; /* i=7 ise 0 olur i parolan&#253;n indisidir*/
			fscanf(dosya,"%c",&ch);
		}
		fclose(dosya);
		fclose(dosya2);
		puts("Decoding completed!");	
	}
	else{
		 puts("Undefined option! Use \"-e\" or \"-d\"");
		 exit(1);
	}	 

return 0;
}