Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <string>
- #include <cctype>
- #include <map>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- //string alph = "abcdefghijklmnopqrstuvwxyz0123456789.?!,;:-";
- string alph = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя0123456789.?!,;:-\'\"";
- int main()
- {
- setlocale(LC_CTYPE, "Russian");
- ifstream in("input.txt");
- ofstream out("output.txt");
- string str;
- map <string, unsigned char> map_table_first;
- map <unsigned char, string> map_table_second;
- string start = "000000";
- for (int i = 0; i < (int)alph.size(); i++)
- {
- map_table_first[start] = (unsigned char)alph[i];
- map_table_second[(unsigned char)alph[i]] = start;
- if (i == (int)alph.size() - 1)
- break;
- for (int j = (int)start.size() - 1; j >= 0; j--)
- {
- if (start[j] == '0')
- {
- start[j] = '1';
- break;
- }
- else
- start[j] = '0';
- }
- }
- unsigned char c;
- unsigned int A = 2;
- //unsigned int A = 3;
- unsigned int C = 7;
- unsigned int x = 6;
- //unsigned int x = 3;
- unsigned int m = alph.size();
- while (!in.eof())
- {
- {
- getline(in, str);
- for (int i = 0; i < (int)str.size(); i++)
- {
- c = (unsigned char)str[i];
- c = tolower(c);
- if (c == ' ')
- {
- out << c;
- continue;
- }
- string s1 = map_table_second[c];
- string s2 = map_table_second[(unsigned char)alph[x]];
- string sum = "";
- for (int i = 0; i < (int)s1.size(); i++)
- {
- if (s1[i] == '1')
- sum += (s2[i] == '1' ? '0' : '1');
- else
- sum += (s2[i] == '0' ? '0' : '1');
- }
- if (sum > start)
- out << map_table_first[start];
- else
- out << map_table_first[sum];
- x = (A * x + C) % m;
- }
- out << endl;
- }
- }
- in.close();
- out.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement