Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. string szyfrowanie(string txt, string klucz)
  2. {
  3.     for (int i = 0; i < txt.size(); i++)
  4.     {
  5.         int znakTekst = txt[i] - 'A';
  6.         int znakKlucz = klucz[i % klucz.length()] - 'A';
  7.         txt[i] = (char)((znakTekst ^ znakKlucz) + 'A');
  8.     }
  9.     return txt;
  10. }
  11.  
  12. int main()
  13. {
  14.     string txt, klucz;
  15.     cout << "Podaj klucz (od B do Z): ";
  16.     cin >> klucz;
  17.     cout << "Podaj tekst jawny: ";
  18.     cin >> txt;
  19.     cout << "Szyfrogram to: ";
  20.     cout << szyfrowanie(txt, klucz)<<endl;
  21.     cout << "Po rozszyfrowaniu: ";
  22.     cout << szyfrowanie(szyfrowanie(txt, klucz), klucz);
  23.  
  24.     getch();
  25.     return 0;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement