Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string zakoduj_wiadomosc(string wiadomosc)
- {
- string zakodowana = "";
- string alfabet = "abcdefghijklmnopqrstuvwxyz";
- for(int i = 0; i < wiadomosc.length(); i++)
- {
- if (wiadomosc[i] >= 'a' && wiadomosc[i] <= 'z')
- {
- int index = wiadomosc[i] - 'a';
- if(index == 0)
- {
- index = 25;
- }
- else
- {
- index = index - 1;
- }
- zakodowana += alfabet[index];
- }
- else
- {
- zakodowana += wiadomosc[i];
- }
- }
- return zakodowana;
- }
- string odkoduj_wiadomosc(string wiadomosc)
- {
- string odkodowana = "";
- string alfabet = "abcdefghijklmnopqrstuvwxyz";
- for(int i = 0; i < wiadomosc.length(); i++)
- {
- if (wiadomosc[i] >= 'a' && wiadomosc[i] <= 'z')
- {
- int index = wiadomosc[i] - 'a';
- if(index == 25)
- {
- index = 0;
- }
- else
- {
- index = index + 1;
- }
- odkodowana += alfabet[index];
- }
- else
- {
- odkodowana += wiadomosc[i];
- }
- }
- return odkodowana;
- }
- int main() {
- cout <<"Witaj w programie Lamacz kodow !" << endl;
- cout << "Wybierz opecacje:"<<endl;
- cout << "1. Zakoduj wiadomosc." << endl;
- cout <<"2. Odkoduj wiadomosc."<<endl;
- int wybor = 0;
- cin >> wybor;
- cin.ignore();
- string wiadomosc = "";
- cout << "Wprowadz wiadomosc: ";
- getline(cin, wiadomosc);
- if(wybor == 1)
- {
- string zakodowana = zakoduj_wiadomosc(wiadomosc);
- cout << zakodowana << endl;
- }
- else if(wybor == 2)
- {
- string odkodowana = odkoduj_wiadomosc(wiadomosc);
- cout << odkodowana << endl;
- }
- else
- {
- cout << "Nieprawidlowa wartosc :("<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment