arturParchem

Cezar z kodem

Mar 7th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5. string napis;
  6. int kod,klucz;
  7. void SzyfrW(char a)
  8. {
  9. if(int(a)+3<=122)
  10.     {
  11.         cout<<char(int(a)+klucz);
  12.     }
  13.     else
  14.     {
  15.         cout<<char(int(a)+klucz-26);
  16.     }
  17. }
  18. void SzyfrM(char a)
  19. {
  20. if(int(a)+3<=90)
  21.     {
  22.         cout<<char(int(a)+klucz);
  23.     }
  24.     else
  25.     {
  26.         cout<<char(int(a)+klucz-26);
  27.     }
  28.  
  29. }
  30. void rozM(char a)
  31. {
  32.     if(int(a)-klucz>=97)
  33.     {
  34.         cout<<char(int(a)-klucz);
  35.     }
  36.     else
  37.     {
  38.         cout<<char(int(a)+26-klucz);
  39.     }
  40.  
  41. }
  42. void rozW(char a)
  43. {
  44.     if(int(a)-klucz>=65)
  45.     {
  46.         cout<<char(int(a)-klucz);
  47.     }
  48.     else
  49.     {
  50.         cout<<char(int(a)+26-klucz);
  51.     }
  52. }
  53. void szyfrowanie(char *teskt,int przesu)
  54. {
  55.  
  56. }
  57. int main()
  58. {
  59.     cout<<"podaj napis do zaszyfrowania"<<endl;
  60.     getline(cin,napis);
  61.     cout<<"podaj klucz: ";
  62.     cin>>klucz;
  63.     klucz=klucz%26;
  64.     cout<<"1.Rozszyfruj 2. zaszyfruj"<<endl;
  65.     cin>>kod;
  66.     cout<<endl;
  67.     int dl= napis.size();
  68.     int klucze[int(dl)];
  69.     if(kod == 2)
  70.     {
  71.         for(int i=0;i<dl;i++)
  72.         {
  73.             if(int(napis[i])>=65&&int(napis[i])>=90)
  74.             {
  75.                 SzyfrW(napis[i]);
  76.             }else if(int(napis[i])==32)
  77.             {
  78.             cout<<" ";
  79.             }else
  80.             {
  81.             SzyfrM(napis[i]);
  82.             }
  83.  
  84.         }
  85.     }
  86.     if(kod == 1)
  87.     {
  88.         for(int j=0;j<dl;j++)
  89.         {
  90.             if(int(napis[j])>=65&&int(napis[j])<=90)
  91.             {
  92.                 rozW(napis[j]);
  93.             }else if(int(napis[j])==32)
  94.             {
  95.             cout<<" ";
  96.             }else
  97.             {
  98.             rozM(napis[j]);
  99.             }
  100.  
  101.         }
  102.     }
  103.  
  104.  
  105.  
  106.     return 0;
  107. }
Add Comment
Please, Sign In to add comment