Advertisement
Frinom

lab7

Nov 11th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <windows.h>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. const char* finName = "D:\\Programming\\lab7\\lab7\\textIn.txt";
  9. const char* foutName = "D:\\Programming\\lab7\\lab7\\textOut.txt";
  10. const char* keysName = "D:\\Programming\\lab7\\lab7\\keys.txt";
  11.  
  12. int main()
  13. {
  14.     SetConsoleCP(1251);
  15.     SetConsoleOutputCP(1251);
  16.     ifstream fin;
  17.     fin.open(finName, ios::in);
  18.     ofstream keysIn;
  19.     keysIn.open(keysName);
  20.     unsigned char arr1[50], arr2[30];
  21.     int keys[5000] = {}, ind = 0, stat[256] = {};
  22.     while (!fin.eof())
  23.     {
  24.         fin >> arr1;
  25.         for (int i = 0; arr1[i] != '\0'; i++)
  26.             keys[ind] += (arr1[i] - '0');
  27.         keys[ind] %= 256;
  28.         keysIn << keys[ind] << " ";
  29.         ind++;
  30.     }
  31.     fin.seekg(0, ios_base::beg); fin.close(); fin.open(finName);
  32.     ofstream fout;
  33.     fout.open(foutName);
  34.     unsigned char sym1 = NULL;
  35.     int iterator = 0;
  36.     while (true)
  37.     {
  38.         if (iterator == ind)
  39.             iterator = 0;
  40.         fin >> noskipws >> sym1;
  41.         if (fin.eof())
  42.             break;
  43.         if (sym1 != ' ' && sym1 != '\n')
  44.         {
  45.             fout << (unsigned char)(((int)(sym1) ^ keys[iterator]));
  46.             iterator++;
  47.         }
  48.         else
  49.             fout << sym1;
  50.     }
  51.     fout.close();
  52.     fin.seekg(0, ios_base::beg); fin.close(); fin.open(finName);
  53.     ifstream foutIn;
  54.     foutIn.open(foutName);
  55.     cout << "Введите исследуемый символ: ";
  56.     unsigned char sym;
  57.     unsigned char sym2;
  58.     cin >> sym;
  59.     while (true)
  60.     {
  61.         fin >> sym1;
  62.         foutIn >> sym2;
  63.         if (fin.eof())
  64.             break;
  65.         if (sym1 == sym)
  66.             stat[(unsigned int)(sym2)]++;
  67.     }
  68.     fin.close();
  69.     foutIn.close();
  70.     for (int i = 0; i < 256; i++)
  71.     {
  72.         cout << setw(4) << stat[i] << " ";
  73.         if ((i + 1) % 16 == 0)
  74.             cout << endl;
  75.     }
  76.     system("pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement