-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathszyfr_cezara.cpp
37 lines (29 loc) · 878 Bytes
/
szyfr_cezara.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
#include <iostream>
std::string szyfruj(std::string slowo, std::string alfabet, int k) {
k %= alfabet.length();
std::string wynik = "";
for(int i = 0; i < slowo.length() ; i++) {
if(char(slowo[i]) == 32) wynik += " ";
else {
slowo[i] = tolower(slowo[i]);
for(int j = 0; j < alfabet.length(); j++)
if(slowo[i] == alfabet[j]){
wynik += alfabet[(j + k) % alfabet.length()];
break;
}
}
}
return wynik;
}
int main(int argc, char** argv) {
int k;
std::string slowo;
std::string alfabet = "abcdefghijklmnopqrstuvwxyz";
std::cout << "Podaj slowo: ";
std::getline(std::cin, slowo);
std::cout << "Podaj klucz: ";
std::cin >> k;
std::cout << szyfruj(slowo, alfabet, k) << std::endl;
return 0;
}