zoukankan      html  css  js  c++  java
  • 序列加密

     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 }
  • 相关阅读:
    [bzoj1934][Shoi2007]Vote 善意的投票
    [bzoj1834][ZJOI2010]network 网络扩容
    [bzoj2127]happiness
    [bzoj3876][Ahoi2014]支线剧情
    [bzoj1927][Sdoi2010]星际竞速
    [bzoj3223]Tyvj 1729 文艺平衡树
    [bzoj3224]Tyvj 1728 普通平衡树
    FJOI2017 RP++
    [bzoj3529][Sdoi2014]数表
    异步ajax请求数据处理
  • 原文地址:https://www.cnblogs.com/luoweiKnowledge/p/4173623.html
Copyright © 2011-2022 走看看