序列加密

 1 #include <iostream>
 2 
 3 using namespace std;
 4 bool Encrypt(const char szText[],unsigned int nTextLen,
 5              char szOutString[],unsigned int nOutLen)
 6              {
 7 
 8              if(nTextLen<=0 || nOutLen<nTextLen)
 9              {
10 
11              return false;
12 
13              }
14              char chLetter;
15              for(int i=0;i<nTextLen-1;i++)
16              {
17                  chLetter=szText[i]+i+10;
18                  szOutString[i]=chLetter;
19              }
20              szOutString[nTextLen-1]='';
21              return true;
22              }
23 bool Decrypt(const char  szText[],unsigned int nTextLen,
24              char szOutString[],unsigned int nOutLen)
25              {
26                  if(nTextLen<=0 || nOutLen<nTextLen)
27                  {
28                      return false;
29                  }
30                  char chLetter;
31              for(int i=0;i<nTextLen-1;i++)
32              {
33                  chLetter=szText[i]-i-10;
34                  szOutString[i]=chLetter;
35              }
36              szOutString[nTextLen-1]='';
37              return true;
38              }
39 
40 
41 int main()
42 {
43     char szText[]="hello world";
44     char szRet[sizeof(szText)/sizeof(char)]={0};
45     char szDecrypt[sizeof(szText)/sizeof(char)]={0};
46     if(Encrypt(szText,sizeof(szText),szRet,sizeof(szRet)/sizeof(char)))
47     {
48         cout<<szText<<"的密文是:"<<szRet<<endl;
49     }
50      if(Decrypt(szRet,sizeof(szRet)/sizeof(char),szDecrypt,sizeof(szDecrypt)/sizeof(char)))
51     {
52 
53         cout<<szRet<<""<<"的明文是:"<<szDecrypt<<endl;
54 
55     }
56     return 0;
57 }
原文地址:https://www.cnblogs.com/luoweiKnowledge/p/4173623.html