首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

各位,能不能把上面这段代码该写一上:实现加密函数调用解密函数(就是把加密和解密封装为两个函数),那里面的参数怎样定义呀…呀

2012-08-17 
各位,能不能把下面这段代码该写一下:实现加密函数调用解密函数(就是把加密和解密封装为两个函数),那里面的

各位,能不能把下面这段代码该写一下:实现加密函数调用解密函数(就是把加密和解密封装为两个函数),那里面的参数怎样定义呀……急呀!
#include <conio.h>  
#include <memory.h> 
#include <string.h> 
#include <stdio.h> 
#include <time.h>
#include <stdlib.h>

void Encrypt() 

  char szInput[80]; 
  char szOutput[80]; 
  int n,nLen,i,k; 
   
   
  srand((unsigned int)time(NULL));

  k= rand()%10+1;
  printf("%d\n",k);

}
}
 
  // 输入待加密字符串. 
  printf( "Input string:%s\n "); 
  gets(szInput); 
  nLen = strlen(szInput); 

  // 加密. 
  for(n = 0; n < nLen; n ++) 
  { 
  if(n % 2)
  szOutput[n] = szInput[n] ^ n; 
  else szOutput[n] = szInput[n] + k; 
  } 
  szOutput[n] = 0; 
  // 输出加密后的字符串. 
  printf( "Output string:%s\n ", szOutput); 
  Dencrypt(k,nLen,szInput,szOutput);
   

  // 清空保存源串的字符数组. 
  memset(szInput, 0, 80 * sizeof(char)); 
  int n = 0;  
  // 解密. 
  for(n = 0; n < nLen; n ++) 
  { 
  if(n % 2) 
  *szInput[n] = *szOutput[n] ^ n; 
  else *szInput[n] = *szOutput[n] - k; 
  } 

  *szInput[n] = 0; 
  // 输出源串. 
  printf( "Source string:%s\n ", *szInput); 
}



[解决办法]
楼主你要的是这个效果吧

C/C++ code
#include <conio.h>   #include <memory.h>  #include <string.h>  #include <stdio.h>  #include <time.h>#include <stdlib.h>void Encrypt(char input[80],int  len);  //你问的是参数怎么写吧参数名字和你的void NoEncrypt(char input[80],int len);//szinput szoutput都不搭界  爱怎么写就怎么写int k= 1000;int main (){    char szInput[80];      char szOutput[80];      int nLen,i;      printf( "Input string:%s\n ");      gets(szInput);      nLen = strlen(szInput);  //加密函数    Encrypt(szInput,nLen);    return 0;}void Encrypt(char input[80],int len){   char szOutput[80];    int n;  for(n = 0; n < len; n ++)    {       if(n % 2)        szOutput[n] = input[n] ^ n;      else         szOutput[n] = input[n] + k;    }    szOutput[n] = 0;    // 输出加密后的字符串.    printf( "Output string:%s\n ", szOutput);    //加密函数里调用解密解密函数  NoEncrypt(szOutput,len);}void NoEncrypt(char input[80],int len){    char szinput[80];    int n;    for(n = 0; n < len; n ++)      {          if(n % 2)              *szinput[n] = *input[n] ^ n;          else             *szinput[n] = *input[n] - k;        }*szinput[n] = 0;  } 

热点排行