华为OJ_2128_字符串加解密
来源:互联网 发布:淘宝美工兼职怎么样 编辑:程序博客网 时间:2024/05/16 05:30
接口描述:
实现接口,每个接口实现1个基本操作:
void Encrypt (char aucPassword[], char aucResult[])
:在该函数中实现字符串加密并输出
说明:
1、字符串以\0结尾。
2、字符串最长100个字符。
int unEncrypt (char result[], char password[])
:在该函数中实现字符串解密并输出
说明:
1、字符串以\0结尾。
2、字符串最长100个字符。
样例输入:
abcdefg
BCDEFGH
样例输出:
BCDEFGH
abcdefg
#include <iostream>#include <string>#include <cctype>using namespace std;void Encrypt (char aucPassword[], char aucResult[]);void unEncrypt (char result[], char password[]);int main( void ){string sPw1, sPw2, sRst1, sRst2;cin >> sPw1;cin >> sRst2;// const_cast<char*>会使得string不可用,但是str.c_str()仍然可用// str = str.c_str()可以恢复strEncrypt( const_cast<char*>( sPw1.c_str() ), const_cast<char*>( sRst1.c_str() ) );unEncrypt( const_cast<char*>( sRst2.c_str() ), const_cast<char*>( sPw2.c_str() ) );cout << sRst1.c_str() << endl;cout << sPw2.c_str() << endl;return 0;}void Encrypt (char aucPassword[], char aucResult[]){char *pPw = aucPassword;char *pRst = aucResult;while( *pPw != '\0' ){if( islower( *pPw ) ){*pRst = ( *pPw - 'a' + 1 ) % 26 + 'a' + ( 'A' - 'a' );}else if( isupper( *pPw ) ){*pRst = ( *pPw - 'A' + 1 ) % 26 + 'A' + ( 'a' - 'A' );}else if( isdigit( *pPw ) ){*pRst = ( *pPw - '0' + 1 ) % 10 + '0';}else{*pRst = *pPw;}++pPw;++pRst;}*pRst = '\0';}void unEncrypt (char result[], char password[]){char *pRst = result;char *pPw = password;while( *pRst != '\0' ){if( islower( *pRst ) ){*pPw = ( *pRst - 'a' - 1 + 26 ) % 26 + 'a' + ( 'A' - 'a' );}else if( isupper( *pRst ) ){*pPw = ( *pRst - 'A' - 1 + 26 ) % 26 + 'A' + ( 'a' - 'A' );}else if( isdigit( *pRst ) ){*pPw = ( *pRst - '0' - 1 + 10 ) % 10 + '0';}else{*pPw = *pRst;}++pRst;++pPw;}*pPw = '\0';}
0 0
- 华为OJ_2128_字符串加解密
- 【华为OJ】 字符串加解密
- 华为OJ 字符串加解密
- 华为oj: 字符串加解密
- 华为oj_字符串加解密
- 华为oj字符串加解密
- 华为oj:字符串加解密
- 华为oj 字符串加解密
- [华为OJ] 字符串加解密
- 【华为OJ】字符串加解密
- 【华为 OJ 】字符串加解密
- 华为OJ 字符串加解密
- 华为OJ 字符串加解密
- 华为OJ(字符串加解密)
- 华为OJ题库_字符串加解密
- 华为OJ平台题:字符串加解密
- 华为OJ基础篇-字符串加解密
- 【华为OJ】【023-字符串加解密】
- 对于ios7扫描二维码功能的实现
- DPM中的HOG源码的Matlab版重写-《小超教你写论文》系列第四部分第一篇
- 易信公众平台开发从入门到精通之获取凭证利用SAE缓存
- Hbase 创建表 shell 命令
- 云计算的分类
- 华为OJ_2128_字符串加解密
- cocos2dX 之CCParticle
- 如何让搜索引擎了解您的主页
- 内联函数
- windows shell 相关
- Java String类常用方法2 --获取、转换、判断
- 华为OJ_2126_字符串合并处理
- Myeclipse显示文件夹而不是包的结构
- 云计算的概念,现状及关键技术