58.c

来自「原名是:c语言经典教程105例源代码」· C语言 代码 · 共 49 行

C
49
字号
#include<stdio.h>
#include<stdlib.h>
int main()
{
	FILE * sourcefile;
	FILE * keyfile;
	FILE * destfile;
	char ch,keych;
	int i;
	puts("****************************************");
	puts("* The file will encrypt the source.txt *");
	puts("****************************************");
	
	if(!(sourcefile = fopen("source.txt","r")))
 	{
  		printf("Can not open the source file\n");
  		exit(-1);
 	}
	if(!(destfile = fopen("destfile.txt","w+")))
 	{
  		printf("Can not open the destination  file\n");
  		exit(-1);
 	}
	if(!(keyfile= fopen("keyfile.txt","w+")))
 	{
  		printf("Can not open the keyfile  file\n");
  		exit(-1);
 	}
	printf("\n.....Encrypting....\n");
	i = 0;
	while(!feof(sourcefile))
 	{
 		randomize();
		keych = random(112 - i) +16;
		ch = fgetc(sourcefile);
  		ch = ch ^ keych;
  		fputc(ch,destfile);
		fputc(keych,keyfile);
		i = ( ++i)%16;
 	}
	printf("Encrypted the souce.txt successfully!\n");
	fclose(sourcefile);
	fclose(keyfile);
	fclose(destfile);
	getch();
	return 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?