求助!要做一个文件加密解密系统,但运行时输入文件名无法打开,解密也没法进行
文件那章老师没讲,所以我是照着书瞎搞的==系统有一个保护密码, 输入密码则可运行,然后加密解密,操作时需要输入相同的密钥。还可以修改保护密码。用的软件是Dev c++
检查的时候栏里显示【错误】id returned 1 exist status,这个是什么意思?
#include <stdio.h>
#include <stdlib.h>
void encrypt(FILE *fp_scr,char *key,FILE *fp_dest);
void XiuGai();
void jiemi();
void jiami();
int b=123;
int main () {
char ch;
int i,a,c;
printf("input password:");
scanf("%d",&a);
if(a==b){
do{
system("cls");
for(i=0;i<50;i++)
printf("*");
printf("\n");
printf("\t 1: 加密\n");
printf("\t 2: 解密\n");
printf("\t 3: 改密\n");
printf("\t 4: 退出\n");
for(i=0;i<50;i++)
printf("*");
printf("\n");
do{
printf("\t 操作");
ch=getchar();
fflush(stdin);
if ((ch>='1')&&(ch<='4'))
break ;
}while((ch<'1')||(ch>'4'));
switch (ch){
case '1':jiami(); break;
case '2':jiemi(); break;
case '3':XiuGai(); break;
case '4':exit(0);
}
system("pause");
}while(1);
}else
printf("wrong!\n");
return 0;
}
void encrypt(FILE *fp_scr,char *key,FILE *fp_dest){
char buff[50];
int len,i;
while ((len=fread(buff,sizeof(char),5,fp_scr))>0){
for(i=0;i<len;i++)
buff[i] ^=key[i];
fwrite(buff,sizeof(char),len,fp_dest);
}
}
void XiuGai()
{
int a=0,c=0;
int i=0;
do
{
printf("pre password?");
scanf("%d",&a);
if(a!=123)
{
printf("wrong?\n");
}
else
{
break;
}
}while(1);
printf("new password?\n");
scanf("%d",&a);
b=a;
}
void jiami(){
char ch,filename[50],key[5];
FILE *fp1,*fp2;
printf("input 5 words:");
scanf("%s",key);
printf("input a file:");
scanf("%s",filename);
fp1=fopen(filename,"r");
fp2=fopen("jiami.txt","w");
if(fp1==NULL||fp2==NULL){
printf("error!\n");
}
encrypt(fp1,key,fp2);
fclose(fp1);
fclose(fp2);
}
void jiemi(char *key){
char ch,filename[50],key2[5];
FILE *fp1,*fp2;
printf("input 5 words:");
scanf("%s",key2);
if(key2==key){
printf("input a file:");
scanf("%s",filename);
fp1=fopen(filename,"r");
fp2=fopen("jiemi.txt","w");
if(fp1==NULL||fp2==NULL){
printf("error!\n");
}
encrypt(fp1,key,fp2);
fclose(fp1);
fclose(fp2);}else{
printf("wrong!\n");
}
}
[此贴子已经被作者于2015-12-30 19:59编辑过]