清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐随机加密程序的实现方法,无聊中的都看过来。
【 tulaoshi.com - 编程语言 】
利用异或的性质来对文件进行加密:
代码如下:
c=a^b
c^b=a
#include "stdio.h"
#include "stdlib.h"
void main(int argc,char *argv[])
{
 FILE *fp1,*fp2;
 char c,ch;
 long j;
 if(3!=argc)
 {
  printf("Command error/n");
  exit(1);
 }
 if((fp1=fopen(argv[1],"rb"))==NULL)
 {
  printf("Can not open the source file/n");
  exit(1);
 }
 if(NULL==(fp2=fopen(argv[2],"wb")))
 {
  printf("Can not open the aim file/n");
  exit(1);
 }
 printf("Please input the password:/n");
 scanf("%i",&j);
 srand(j);
 ch=fgetc(fp1);
 while(!feof(fp1))
 {
  c=rand();
  ch=ch^c;
  fputc(ch,fp2);
  ch=fgetc(fp1);
 }
 fclose(fp1);
 fclose(fp2);
}
来源:http://www.tulaoshi.com/n/20160219/1592835.html