ademosh

9 задание XoR

Nov 10th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include "pch.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7.  
  8.  
  9. using namespace std;
  10. //Объявляем массив символов русского и английского алфавита
  11. string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя,-.";
  12. int code(char str)
  13. {
  14.     for (int i = 0; i < 33; i++) {
  15.         if (str == alpha[i])
  16.             return i;
  17.     }
  18. }
  19.  
  20. int main() {
  21.     system("chcp 1251");
  22.     system("cls");
  23.     setlocale(LC_ALL, "Russian");
  24.     ifstream start("start.txt");
  25.     ofstream output("out.txt");
  26.     char alphaB[20][2];
  27.     string message;
  28.     string key;
  29.     string decode;
  30.     getline(start, key);
  31.     getline(start, message);
  32.     cout << endl;
  33.     int o;
  34.     int ukazi = 0;
  35.     int ukazj = 0;
  36.     for (int i=0;i<message.length();++i) {
  37.         char buf = (message[i] ^ key[i%key.length()]);
  38.         output <<buf<<' ';
  39.         decode += buf;
  40.     }
  41.  
  42.     for (int i = 0; i < decode.length(); ++i) {
  43.         char buf = (decode[i] ^ key[i%key.length()]);
  44.         cout << buf << ' ';
  45.     }
  46.     cout << endl;
  47.     system("pause");
  48.     return 0;
  49. }
Add Comment
Please, Sign In to add comment