操作系统文件加密
编程实现文件加密
1 #include<stdio.h> 2 #include<unistd.h> 3 #include<fcntl.h> 4 void main() 5 { 6 int fd1,fd2; 7 char ch; 8 if((fd1=open("5.txt",O_RDONLY))!=-1) 9 { 10 if((fd2=open("6.txt",O_WRONLY))!=-1) 11 { 12 while(read(fd1,&ch,1)==1) 13 { 14 ch=ch^'a'; 15 write(fd2,&ch,1); 16 17 } 18 printf("5.txt加密成功,加密文件为6.txt\n"); 19 } 20 close(fd2); 21 } 22 close(fd1); 23 if((fd1=open("6.txt",O_RDONLY))!=-1) 24 { 25 if((fd2=open("7.txt",O_WRONLY))!=-1) 26 { 27 while(read(fd1,&ch,1)==1) 28 { 29 ch=ch^'a'; 30 write(fd2,&ch,1); 31 } 32 printf("6.txt解密成功,解密文件为7.txt\n"); 33 } 34 close(fd2); 35 } 36 close(fd1); 37 }