首页 > 其他 > 详细

序列加密

时间:2014-12-19 12:54:11      阅读:268      评论:0      收藏:0      [点我收藏+]

 

 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]=\0;
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]=\0;
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<<"\0"<<"的明文是:"<<szDecrypt<<endl;
54 
55     }
56     return 0;
57 }

 

序列加密

原文:http://www.cnblogs.com/luoweiKnowledge/p/4173623.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!