
#include
"
stdafx.h
"
#include<iostream>
#include<ctime>
using namespace std;
void Makecode( char *pstr, int *pkey);
void Cutecode( char *pstr, int *pkey);
int _tmain( int argc, _TCHAR* argv[])
{
int key[]={ 1, 2, 3, 4, 5}; // 加密字符
char s[]= " www.xiaozhuanggushi.com ";
char *p=s;
cout<< " 加密前: "<<p<<endl;
Makecode(s,key); // 加密
cout<< " 加密后: "<<p<<endl;
Cutecode(s,key); // 解密
cout<< " 解密后: "<<p<<endl;
int c;
cin>>c;
return 0;
}
// 單個字符異或運算
char MakecodeChar( char c, int key){
return c=c^key;
}
// 單個字符解密
char CutcodeChar( char c, int key){
return c^key;
}
// 加密
void Makecode( char *pstr, int *pkey){
int len=strlen(pstr); // 獲取長度
for( int i= 0;i<len;i++)
*(pstr+i)=MakecodeChar(*(pstr+i),pkey[i% 5]);
}
// 解密
void Cutecode( char *pstr, int *pkey){
int len=strlen(pstr);
for( int i= 0;i<len;i++)
*(pstr+i)=CutcodeChar(*(pstr+i),pkey[i% 5]);
}
#include<iostream>
#include<ctime>
using namespace std;
void Makecode( char *pstr, int *pkey);
void Cutecode( char *pstr, int *pkey);
int _tmain( int argc, _TCHAR* argv[])
{
int key[]={ 1, 2, 3, 4, 5}; // 加密字符
char s[]= " www.xiaozhuanggushi.com ";
char *p=s;
cout<< " 加密前: "<<p<<endl;
Makecode(s,key); // 加密
cout<< " 加密后: "<<p<<endl;
Cutecode(s,key); // 解密
cout<< " 解密后: "<<p<<endl;
int c;
cin>>c;
return 0;
}
// 單個字符異或運算
char MakecodeChar( char c, int key){
return c=c^key;
}
// 單個字符解密
char CutcodeChar( char c, int key){
return c^key;
}
// 加密
void Makecode( char *pstr, int *pkey){
int len=strlen(pstr); // 獲取長度
for( int i= 0;i<len;i++)
*(pstr+i)=MakecodeChar(*(pstr+i),pkey[i% 5]);
}
// 解密
void Cutecode( char *pstr, int *pkey){
int len=strlen(pstr);
for( int i= 0;i<len;i++)
*(pstr+i)=CutcodeChar(*(pstr+i),pkey[i% 5]);
}