Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "funcs.h"
- int main()
- {
- //SetConsoleCP(1251); SetConsoleOutputCP(1251);
- system("chcp 1251 > nul");
- //setlocale(LC_ALL, "Russian");
- unsigned char line1;
- //char line;
- unsigned char l;
- unsigned int sum = 0;
- int i = 0;
- int A[256][256];
- for (int i = 0; i < 256; i++)
- {
- for (int j = 0; j < 256; j++)
- {
- A[i][j] = 0;
- }
- }
- // ( чтение )
- ifstream fin("key1.txt", ios::in | ios::binary);
- if (!fin) // cotrol
- {
- cout << "Error of file opening." << endl;
- return 1;
- }
- l = '.';
- bool fl = true;
- int kol = 0; // длина массива ключей
- while (fin.get((char&)line1)) /// кол-во слов
- {
- //line1 = fin.get();
- if((l != ' ') && ((line1 == ' ') || (line1 == ' ')))
- {
- kol++;
- }
- l = line1;
- }
- //if ((line1 != ' ') && (line1 != '\n')) { kol++; }
- fl = false;
- unsigned char* key = new unsigned char[kol];
- fin.clear();
- fin.seekg(0);
- unsigned char t;
- while (fin.get((char&)line1)) /// массив ключей
- {
- //line1 = fin.get();
- if ((line1 == ' ') || (line1 == '\n'))
- {
- fl = true;
- }
- else
- {
- if (fl)
- { t = sum % 256;
- key[i] = t;
- sum = 0;
- i++;
- }
- sum = sum + line1;
- fl = false;
- }
- }
- //sum = sum - line1;
- //key[i] = sum % 256;
- // массив заполнен юху-у-у-у!
- fin.close();
- ifstream text("text.txt", ios::in | std::ios::binary);
- if (!text.is_open()) // cotrol
- {
- cout << "Error of file opening." << endl;
- return 1;
- }
- ofstream crypt("crypt.txt", ios::out | std:: ios::binary);
- if (!crypt.is_open()) // cotrol
- {
- cout << "Error of file opening." << endl;
- return 1;
- }
- i = 0; // запись кодирование
- unsigned char cEOF = (unsigned char)(EOF);
- while (text.get((char&)line1))
- {
- //line1 = text.get();
- cout << line1;
- /*if (line1 == cEOF)
- {
- break;
- }*/
- l = (unsigned char)((int)(line1) ^ key[i]);
- A[( unsigned char)(line1)][(unsigned char)(line1) ^ key[i]]++;
- crypt << l;
- i++;
- if (i == kol-1) { i = 0; }
- }
- crypt.close();
- text.close();
- ////// декодирование
- ifstream code("crypt.txt", ios::in | std::ios::binary);
- if (!code.is_open()) // cotrol
- {
- cout << "Error of file opening code." << endl;
- return 1;
- }
- ofstream decode("decode.txt", ios::out | std::ios::binary);
- if (!decode.is_open()) // cotrol
- {
- cout << "Error of file opening decode." << endl;
- return 1;
- }
- cout << endl;
- cout << endl;
- i = 0; // запись декодирование
- while (code.get((char&)(line1)))
- {
- l = (unsigned char)((int)(line1) ^ key[i]);
- //cout << l;
- decode << l;
- i++;
- if (i == kol - 1) { i = 0; }
- }
- cout<<endl;
- decode.close();
- code.close();
- // statistic
- st(A);
- return 0;
- }
Add Comment
Please, Sign In to add comment