1 Star 0 Fork 0

zebulon2020 / Decryption

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
zebulon2020 提交于 2020-09-12 13:52 . a small change
#include <iostream>
using namespace std;
class Decryption{
public:
void getDecryption(char* s);
};
void Decryption::getDecryption(char* s){
char *ptr = s;
int len = 0; // 字符串的长度
while(*ptr!='\0'){
/* 大小写转换 */
if(*ptr>='a' && *ptr<='z'){
*ptr = char(*ptr + 'A' - 'a');
len++;
}
else{
*ptr = char(*ptr + 'a' - 'A');
len++;
}
ptr++;
}
//cout<<s<<endl;
//cout<<len<<endl;
int i;
char ss[len+1];
for(i=0; i<len; i++){
/*逆序存储到ss这个字符数组中*/
ss[i] = s[len-i-1];
}
ss[len] = '\0';
//cout<<ss<<endl;
ptr = ss;
while(*ptr != '\0'){
/* 移位操作,根据ASCII码。注意xyz(XYZ)右移三位要对应abc(ABC),所以要分两种情况 */
if(*ptr=='x'|| *ptr=='y'||*ptr=='z'||*ptr=='X'||*ptr=='Y'||*ptr=='Z'){
*ptr = char(*ptr - 23);
}
else{
*ptr = char(*ptr + 3);
}
ptr++;
}
cout<<ss<<endl;
}
int main()
{
char s[50]; // 密文
char s2[50]; // 密文的副本
cout<<"请输入密文:"<<endl;
cin>>s;
int i;
for(i=0; i<50; i++){
s2[i] = s[i];
}
Decryption dec; // 解密类的一个对象dec
dec.getDecryption(s2);
//cout<<'A'-'a'<<endl; // 'a'-'A'=32
return 0;
}
C++
1
https://gitee.com/zebulon2020/decryption.git
git@gitee.com:zebulon2020/decryption.git
zebulon2020
decryption
Decryption
master

搜索帮助