| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 788 人关注过本帖
标题:c加密程序求助,编译不出来,哪位大侠给改改,不胜感激
只看楼主 加入收藏
tswyayun
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
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 编辑 ]
搜索更多相关主题的帖子: 改改 编译 感激 
2010-06-27 18:45
方廷
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:47
专家分:176
注 册:2010-6-9
收藏
得分:10 
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
void encryption(char *str)
{
  int i;
  char ch;
  FILE *fp;
    for (i=0;str[i]!='\0'; i++)
     {
         str[i] = str[i]^ch;
     }
     i=0;
     if((fp=fopen("d:/123.txt","w"))==NULL)
     {
         printf("error");
     exit(0);
     }
     fputs(str, fp);
     fclose(fp);
}
void decrypt()
{
   int i=0,key;
   char str[MAX],fname[20],c,ch=45;
   FILE *fp;
   printf("输入要解密文件的路径\n");
      scanf("%s", fname);
   printf("请输入密钥\n");
      scanf("%d",&key);
     if( (fp = fopen(fname,"r+")) ==NULL)
     {
         printf("error");
     exit(0);
     }
     while( (c = fgetc(fp)) != EOF)
     {
         c = c^ch;
         str[i] = c;
         i++;
     }
     str[i]='\0';
     printf("%s\n", str);
     fclose(fp);
}
void menu()
{
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Quit\n");
}
  void main()
{
     FILE *fp;
     char c,ch;
     char str[MAX];
     int i=0,key,num=1;
     printf("输入要加密的字符串\n");
     while ( (c= getchar()) != '\n')
     {
         str[i] = c;
         i++;
     }
     str[i] = '\0';
     printf("%s\n",str);
     if( (fp = fopen("d:/test.txt","w+")) ==NULL)
     {
         printf("error");
     exit(0);
     }
  printf("请输入密钥\n");
     scanf("%d",&key);
     fputs(str, fp);
     fclose(fp);
  while(num>0&&num<3)
  {
  menu();
  scanf("%d",&num);
  switch(num)
  {
  case 1:encryption(str);break;
  case 2:decrypt();break;
  default:break;
  }
}
}
2010-06-27 19:57
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:10 
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
void encryption(char *str)
{
  int i;
  char ch;
  FILE *fp;
    for (i=0;str[i]!='\0'; i++)
     {
         str[i] = str[i]^ch;
     }
     i=0;
     if((fp=fopen("d:/123.txt","w"))==NULL)
     {
         printf("error");
     exit(0);
     }
     fputs(str, fp);
     fclose(fp);
}
void decrypt()
{
   int i=0,key;
   char str[MAX],fname[20],c,ch=45;
   FILE *fp;
   printf("输入要解密文件的路径\n");
      scanf("%s", fname);
   printf("请输入密钥\n");
      scanf("%d",&key);
     if( (fp = fopen(fname,"r+")) ==NULL)
     {
         printf("error");
     exit(0);
     }
     while( (c = fgetc(fp)) != EOF)
     {
         c = c^ch;
         str[i] = c;
         i++;
     }
     str[i]='\0';
     printf("%s\n", str);
     fclose(fp);
}
void menu()
{
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Quit\n");
}
  void main()
{
     FILE *fp;
     char c,ch;
     char str[MAX];
     int i=0,key,num=1;
     printf("输入要加密的字符串\n");
     while ( (c= getchar()) != '\n')
     {
         str[i] = c;
         i++;
     }
     str[i] = '\0';
     printf("%s\n",str);
     if( (fp = fopen("d:/test.txt","w+")) ==NULL)
     {
         printf("error");
     exit(0);
     }
  printf("请输入密钥\n");
     scanf("%d",&key);
     fputs(str, fp);
     fclose(fp);
  while(num>0&&num<3)
  {
  menu();
  scanf("%d",&num);
  switch(num)
  {
  case 1:encryption(str);break;
  case 2:decrypt();break;
  default:break;
  }
}
}
应该是这样的,而二楼正确

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-06-28 10:33
tswyayun
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-4-24
收藏
得分:0 
回复 3楼 sunyh1999
我编译过咋不能加密呢,能给加上个加密后保存功能不,给点程序运行截图,谢谢!

2010-06-28 11:48
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:0 
要么我写个函数好了
void password()
{
     long b;
      printf ("请输入管理员密码!\n");
      scanf ("%d",&b);
      if (b!=65040271)
      {printf ("密码错误!\n");return;}
      else
       printf ("密码正确!欢迎进入系统o(∩_∩)o,请输入");
      

}

只是C语言函数不支持加“*”号,你试试吧

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-06 09:16
lovemengx
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2011-02-03 18:51
快速回复:c加密程序求助,编译不出来,哪位大侠给改改,不胜感激
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036467 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved