有没有听说过凯撒密码?
#include<iostream>
#include<string>
using std::endl;
using std::cout;
using std::cin;
int main(){
std::string input;
int count=0, length, n;
cout<<"enter your message to encrypt:\n";
getline(cin,input);
cout<<"enter number of shifts in the alphabet:\n";
cin>>n;
length=input.length();//check for phrase's length
for(count=0;count<length;count++){
if(std::isalpha(input[count])){
//lower case
input[count]=tolower(input[count]);
for(int i=0;i<n;i++){
//if alphbet reaches the end, it starts from the beginning again
if(input[count]=='z')
input[count]='a';
else
input[count]++;
}
}
}
cout<<"your encrypted message: \n"<<input<<endl;
return 0;
}
到目前为止您尝试过什么?正如经常指出的那样,SO不是一项免费编码服务。 – owacoder
这就是我所做的至今,因为我不知道如何做到这一点,我不明白如何转换字符串中的每个字符,而不使用一些复杂的东西......(我刚开始学习,所有我知道的是非常基础)。 –
我在Google和YouTube上到处寻找,并看到很多类似的东西,例如用数字转换一系列字母或用另一个字母转换输入中的每个字母,但似乎没有人问过这个。我只是要求一个小技巧,我不会要求某人为我编程,我只是想了解C++ –