mengatur pergeseran cesar enkripsi
#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
std::string lowerCase = "abcdefghijklmnopqrstuvwxyz";
std::string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string strInput;
std::string strOutput;
int shift = 0;
int found;
std::cout<<"Masukkan kata = \t";
getline(std::cin, strInput);
while (shift ==0 || shift>25){
std::cout<<"Masukkan pergeseran = \t";
std::cin>>shift;
if(shift >25){
std::cout<<"tidak bisa lebih dari 25\n";
}
}
for (int i=0;i<strInput.length();i++){
found = lowerCase.find(strInput.at(i)); //pergeseran
if (found == std::string::npos){
found ==upperCase.find(strInput.at(i)); //menampung huruf besar
if (found == std::string::npos){ //menampung perulanyan
strOutput.push_back(strInput.at(i)); // pergeseran
}
else {
if (found+shift>=26){
strOutput.push_back(upperCase.at(found+shift-26)); //upercase
}
else{
strOutput.push_back(upperCase.at(found+shift));
}
}
}
else{
if (found+shift>=26){
strOutput.push_back(lowerCase.at(found+shift-26)); //lowercase
}
else{
strOutput.push_back(lowerCase.at(found+shift));
}
}
}
std::cout<<"hasilnya = \t\t "<<strOutput<<"\n";
return 0;
}
Senin, 21 Maret 2016
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar