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 }
  • 相关阅读:
    acm的STL容器之vector篇
    服务器远程管理方法及centos该装那个
    VB获取对象成员
    获取搜索引擎关键字建议
    IntelliJ IDEA乱码 问题
    排序算法思想
    ubuntu16 开机启动plank
    fail-fast出识
    html 标签过滤、转译、反转译
    (a ==1 && a== 2 && a==3) 有可能是 true 吗?
  • 原文地址:https://www.cnblogs.com/luoweiKnowledge/p/4173623.html
Copyright © 2011-2022 走看看