c加密程序求助,编译不出来,哪位大侠给改改,不胜感激
要求:输入一数据文件和密码,输出对应的加/解密数据文件。读取数据文件,利用异或运算对数据文件内容逐字节进行加/解密运算;将加/解密后的数据写入给定的数据文件。求哪位大侠帮忙看看那个地方不对,给改改,不胜感激!!!!!!!!!#include <stdio.h>
#include <stdlib.h>
#define MAX 100
void encryption()
{
char str[MAX];
FILE* fp;
for (int i=0; str[i] != '\0'; i++)
{
str[i] = str[i] ^ 45;
}
i=0;
if( (fp = fopen("c:\\jiami.txt","w")) < 0)
{
printf("error");
exit(1);
}
fputs(str, fp);
fclose(fp);
void Decrypt()
{
printf("输入要解密文件的路径\n");
scanf("%s", fname);
printf("请输入密钥\n");
scanf("%d",&key);
ch=fgetc(source);
if( (fp = fopen(fname,"r+")) < 0)
{
printf("error");
exit(1);
}
while( (c = fgetc(fp)) != EOF)
{
c = c^45;
str[i] = c;
i++;
}
printf("%s\n", str);
fclose(fp);
return 0;
}
void menu()
{
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Quit\n");
}
int main()
{
FILE* fp;
char c;
char fname[FILENAME_MAX];
char fname2[FILENAME_MAX];
char str[MAX];
int i=0;
printf("输入要加密的字符串\n");
int key;
while ( (c= getchar()) != '\n')
{
str[i] = c;
i++;
}
str[i] = '\0';
printf("%s\n",str);
if( (fp = fopen("c:\\test.txt","w+")) < 0)
{
printf("error");
exit(1);
}
printf("请输入密钥\n");
scanf("%d",&key);
ch=fgetc(source);
fputs(str, fp);
fclose(fp);
switch(choice)
{
case 1:encryption();break;
case 2:decrypt();break;
case 3:break;
}
return 0;
}
}
[ 本帖最后由 tswyayun 于 2010-6-27 18:47 编辑 ]