Advertisement
Guest User

Untitled

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