Glenpl

Untitled

Oct 16th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. class szyfrator
  9. {
  10. private:
  11.     const int domyslne_przesuniecie = 5;
  12.     int dlugosc_napisu = NULL;
  13.     char bufor_znakowy = NULL;
  14.     int bufor_liczbowy = NULL;
  15.  
  16. public:
  17.     string zaszyfruj_dla_cezara(string napis)
  18.     {
  19.         dlugosc_napisu = napis.length();
  20.  
  21.         for (int i = 0; i < dlugosc_napisu; i++)
  22.         {
  23.             bufor_znakowy = napis[i];
  24.             bufor_liczbowy = static_cast<int>(bufor_znakowy);
  25.             bufor_liczbowy += domyslne_przesuniecie;
  26.             bufor_znakowy = static_cast<char>(bufor_liczbowy);
  27.             napis[i] = bufor_znakowy;
  28.         }
  29.  
  30.         return napis;
  31.     }
  32.     string zaszyfruj_dla_cezara(string napis, int przesuniecie_uzytkownika)
  33.     {
  34.         dlugosc_napisu = napis.length();
  35.  
  36.         for (int i = 0; i < dlugosc_napisu; i++)
  37.         {
  38.             bufor_znakowy = napis[i];
  39.             bufor_liczbowy = static_cast<int>(bufor_znakowy);
  40.             bufor_liczbowy += przesuniecie_uzytkownika;
  41.             bufor_znakowy = static_cast<char>(bufor_liczbowy);
  42.             napis[i] = bufor_znakowy;
  43.         }
  44.  
  45.         return napis;
  46.     }
  47.         string odszyfruj_dla_cezara(string napis)
  48.     {
  49.         dlugosc_napisu = napis.length();
  50.  
  51.         for (int i = 0; i < dlugosc_napisu; i++)
  52.         {
  53.             bufor_znakowy = napis[i];
  54.             bufor_liczbowy = static_cast<int>(bufor_znakowy);
  55.             bufor_liczbowy -= domyslne_przesuniecie;
  56.             bufor_znakowy = static_cast<char>(bufor_liczbowy);
  57.             napis[i] = bufor_znakowy;
  58.         }
  59.  
  60.         return napis;
  61.     }
  62.     string odszyfruj_dla_cezara(string napis, int przesuniecie_uzytkownika)
  63.     {
  64.         dlugosc_napisu = napis.length();
  65.  
  66.         for (int i = 0; i < dlugosc_napisu; i++)
  67.         {
  68.             bufor_znakowy = napis[i];
  69.             bufor_liczbowy = static_cast<int>(bufor_znakowy);
  70.             bufor_liczbowy -= przesuniecie_uzytkownika;
  71.             bufor_znakowy = static_cast<char>(bufor_liczbowy);
  72.             napis[i] = bufor_znakowy;
  73.         }
  74.  
  75.         return napis;
  76.     }
  77. };
  78.  
  79. int main()
  80. {
  81.     int zaszyfruj = 0;
  82.  
  83.     cout << "0. ZASZYFRUJ" << endl;
  84.     cout << "1. ODSZYFRUJ" << endl;
  85.  
  86.     cin >> zaszyfruj;
  87.  
  88.     if (zaszyfruj == 0)
  89.     {
  90.         szyfrator prymityw;
  91.         string napis_uzytkownika;
  92.         bool tak_czy_nie;
  93.         cout << "Podaj napis do zaszyfrowania: ";
  94.         cin >> napis_uzytkownika;
  95.         cout << endl;
  96.         cout << "Czy chcesz uzyc standardowego przesuniecia? " << endl;
  97.         cout << "0. NIE" << endl;
  98.         cout << "1. TAK" << endl;
  99.         cout << endl;
  100.         cin >> tak_czy_nie;
  101.  
  102.         if (tak_czy_nie == 0)
  103.         {
  104.             int o_ile;
  105.             cout << endl << endl;
  106.             cout << "O ile ma zostac przesuniety napis?";
  107.             cin >> o_ile;
  108.             cout << endl << endl << endl;
  109.             cout << "Zaszyfrowany napis: ";
  110.             cout << prymityw.zaszyfruj_dla_cezara(napis_uzytkownika, o_ile);
  111.             cout << endl << endl;
  112.         }
  113.  
  114.         if (tak_czy_nie == 1)
  115.         {
  116.             cout << endl << endl << endl;
  117.             cout << "Zaszyfrowany napis: ";
  118.  
  119.             cout << prymityw.zaszyfruj_dla_cezara(napis_uzytkownika);
  120.             cout << endl << endl;
  121.         }
  122.     }
  123.  
  124.     else if (zaszyfruj == 1)
  125.     {
  126.         szyfrator prymityw;
  127.         string napis_uzytkownika;
  128.         int tak_czy_nie;
  129.         cout << "Podaj napis do odszyfrowania: ";
  130.         cin >> napis_uzytkownika;
  131.         cout << endl;
  132.         cout << "Czy chcesz uzyc standardowego przesuniecia? " << endl;
  133.         cout << "0. NIE" << endl;
  134.         cout << "1. TAK" << endl;
  135.         cout << endl;
  136.         tak_czy_nie = getch();
  137.  
  138.         if (tak_czy_nie == 0)
  139.         {
  140.             int o_ile;
  141.             cout << endl << endl;
  142.             cout << "O ile ma zostac przesuniety napis?";
  143.             cin >> o_ile;
  144.             cout << endl << endl << endl;
  145.             cout << "Odszyfrowany napis: ";
  146.             cout << prymityw.odszyfruj_dla_cezara(napis_uzytkownika, o_ile);
  147.             cout << endl << endl;
  148.         }
  149.  
  150.         if (tak_czy_nie == 1)
  151.         {
  152.             cout << endl << endl << endl;
  153.             cout << "Odszyfrowany napis: ";
  154.  
  155.             cout << prymityw.odszyfruj_dla_cezara(napis_uzytkownika);
  156.             cout << endl << endl;
  157.         }
  158.     }
  159.     _getch();
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment