Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- using namespace std;
- class szyfrator
- {
- private:
- const int domyslne_przesuniecie = 5;
- int dlugosc_napisu = NULL;
- char bufor_znakowy = NULL;
- int bufor_liczbowy = NULL;
- public:
- string zaszyfruj_dla_cezara(string napis)
- {
- dlugosc_napisu = napis.length();
- for (int i = 0; i < dlugosc_napisu; i++)
- {
- bufor_znakowy = napis[i];
- bufor_liczbowy = static_cast<int>(bufor_znakowy);
- bufor_liczbowy += domyslne_przesuniecie;
- bufor_znakowy = static_cast<char>(bufor_liczbowy);
- napis[i] = bufor_znakowy;
- }
- return napis;
- }
- string zaszyfruj_dla_cezara(string napis, int przesuniecie_uzytkownika)
- {
- dlugosc_napisu = napis.length();
- for (int i = 0; i < dlugosc_napisu; i++)
- {
- bufor_znakowy = napis[i];
- bufor_liczbowy = static_cast<int>(bufor_znakowy);
- bufor_liczbowy += przesuniecie_uzytkownika;
- bufor_znakowy = static_cast<char>(bufor_liczbowy);
- napis[i] = bufor_znakowy;
- }
- return napis;
- }
- string odszyfruj_dla_cezara(string napis)
- {
- dlugosc_napisu = napis.length();
- for (int i = 0; i < dlugosc_napisu; i++)
- {
- bufor_znakowy = napis[i];
- bufor_liczbowy = static_cast<int>(bufor_znakowy);
- bufor_liczbowy -= domyslne_przesuniecie;
- bufor_znakowy = static_cast<char>(bufor_liczbowy);
- napis[i] = bufor_znakowy;
- }
- return napis;
- }
- string odszyfruj_dla_cezara(string napis, int przesuniecie_uzytkownika)
- {
- dlugosc_napisu = napis.length();
- for (int i = 0; i < dlugosc_napisu; i++)
- {
- bufor_znakowy = napis[i];
- bufor_liczbowy = static_cast<int>(bufor_znakowy);
- bufor_liczbowy -= przesuniecie_uzytkownika;
- bufor_znakowy = static_cast<char>(bufor_liczbowy);
- napis[i] = bufor_znakowy;
- }
- return napis;
- }
- };
- int main()
- {
- bool zaszyfruj;
- cout << "0. ZASZYFRUJ" << endl;
- cout << "1. ODSZYFRUJ" << endl;
- zaszyfruj = getch();
- if (zaszyfruj == false)
- {
- szyfrator prymityw;
- string napis_uzytkownika;
- bool tak_czy_nie;
- cout << "Podaj napis do zaszyfrowania: ";
- cin >> napis_uzytkownika;
- cout << endl;
- cout << "Czy chcesz uzyc standardowego przesuniecia? " << endl;
- cout << "0. NIE" << endl;
- cout << "1. TAK" << endl;
- cout << endl;
- tak_czy_nie = getch();
- if (tak_czy_nie == 0)
- {
- int o_ile;
- cout << endl << endl;
- cout << "O ile ma zostac przesuniety napis?";
- cin >> o_ile;
- cout << endl << endl << endl;
- cout << "Zaszyfrowany napis: ";
- cout << prymityw.zaszyfruj_dla_cezara(napis_uzytkownika, o_ile);
- cout << endl << endl;
- }
- if (tak_czy_nie == 1)
- {
- cout << endl << endl << endl;
- cout << "Zaszyfrowany napis: ";
- cout << prymityw.zaszyfruj_dla_cezara(napis_uzytkownika);
- cout << endl << endl;
- }
- }
- if (zaszyfruj == true)
- {
- szyfrator prymityw;
- string napis_uzytkownika;
- bool tak_czy_nie;
- cout << "Podaj napis do odszyfrowania: ";
- cin >> napis_uzytkownika;
- cout << endl;
- cout << "Czy chcesz uzyc standardowego przesuniecia? " << endl;
- cout << "0. NIE" << endl;
- cout << "1. TAK" << endl;
- cout << endl;
- tak_czy_nie = getch();
- if (tak_czy_nie == 0)
- {
- int o_ile;
- cout << endl << endl;
- cout << "O ile ma zostac przesuniety napis?";
- cin >> o_ile;
- cout << endl << endl << endl;
- cout << "Odszyfrowany napis: ";
- cout << prymityw.odszyfruj_dla_cezara(napis_uzytkownika, o_ile);
- cout << endl << endl;
- }
- if (tak_czy_nie == 1)
- {
- cout << endl << endl << endl;
- cout << "Odszyfrowany napis: ";
- cout << prymityw.odszyfruj_dla_cezara(napis_uzytkownika);
- cout << endl << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment