C++ 加密

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:27:53
我需要一段C++代码,需要让用户输入一段string然后,输入密码最后加密成一段数字。谢谢了

//代码如下,不懂的可以直接HI我

#include"iostream.h"
#include"stdio.h"
#include"string.h"
#define N 200
#define M 20
void Encode(char [] , char [] , char []) ;
void main()
{
char *str_input , * str_output;
char *str_pwd ;
str_input = new char[N] ;
str_output = new char[3*N+1] ;
str_pwd = new char[M] ;

cin>>str_input ;
cin>>str_pwd ;
Encode(str_input , str_pwd , str_output) ;
cout<<str_output<<endl ;
}

//加密方式比较简单,就是将输入的字符串str_input与密码str_pwd取异或,最后将异或的结果中的每个字符都转化为3为数字输出。
void Encode(char in[] , char pwd[] , char out[])
{
int len = strlen(pwd) ;
int i = 0 ,tmp = 0;
while(in[i])
{
in[i++] ^= pwd[i%len] ;
}
for(int j = 0 ; j < i ; j++)
{
tmp = (int)(in[j]) ;
sprintf(&(out[j*3]),"%03d",tmp) ;
}
}

1.加密,是以某种特殊的算法改变原有的信息数据,使得未授