Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <windows.h>
- #include <cstring>
- using namespace std;
- const char* finName = "D:\\Programming\\lab7\\lab7\\textIn.txt";
- const char* foutName = "D:\\Programming\\lab7\\lab7\\textOut.txt";
- const char* keysName = "D:\\Programming\\lab7\\lab7\\keys.txt";
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- ifstream fin;
- fin.open(finName, ios::in);
- ofstream keysIn;
- keysIn.open(keysName);
- unsigned char arr1[50], arr2[30];
- int keys[5000] = {}, ind = 0, stat[256] = {};
- while (!fin.eof())
- {
- fin >> arr1;
- for (int i = 0; arr1[i] != '\0'; i++)
- keys[ind] += (arr1[i] - '0');
- keys[ind] %= 256;
- keysIn << keys[ind] << " ";
- ind++;
- }
- fin.seekg(0, ios_base::beg); fin.close(); fin.open(finName);
- ofstream fout;
- fout.open(foutName);
- unsigned char sym1 = NULL;
- int iterator = 0;
- while (true)
- {
- if (iterator == ind)
- iterator = 0;
- fin >> noskipws >> sym1;
- if (fin.eof())
- break;
- if (sym1 != ' ' && sym1 != '\n')
- {
- fout << (unsigned char)(((int)(sym1) ^ keys[iterator]));
- iterator++;
- }
- else
- fout << sym1;
- }
- fout.close();
- fin.seekg(0, ios_base::beg); fin.close(); fin.open(finName);
- ifstream foutIn;
- foutIn.open(foutName);
- cout << "Введите исследуемый символ: ";
- unsigned char sym;
- unsigned char sym2;
- cin >> sym;
- while (true)
- {
- fin >> sym1;
- foutIn >> sym2;
- if (fin.eof())
- break;
- if (sym1 == sym)
- stat[(unsigned int)(sym2)]++;
- }
- fin.close();
- foutIn.close();
- for (int i = 0; i < 256; i++)
- {
- cout << setw(4) << stat[i] << " ";
- if ((i + 1) % 16 == 0)
- cout << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement