Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int main() {
- srand(time(NULL));
- ifstream key_stream("key.txt");
- ofstream key_stream_out("key_2.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- vector <char> alph;
- forn(i, 26)
- alph.push_back('a' + i);
- forn(i, 10)
- alph.push_back('0' + i);
- random_shuffle(all(alph));
- forn(i, alph.size())
- key_stream_out << alph[i];
- string temp[] = { "A", "D", "F", "G", "V", "X" };
- map <char, string> alph_to_pair;
- forn(i, 6) {
- forn(j, 6) {
- alph_to_pair[alph[i * 6 + j]] = temp[i] + temp[j];
- }
- }
- vector <int> registr;
- string result = "";
- int idx = 0;
- while (!text_stream.eof()) {
- string temp;
- text_stream >> temp;
- forn(i, temp.size()) {
- if (temp[i] >= 'A' && temp[i] <= 'Z')
- temp[i] += 'a' - 'A', registr.push_back(idx);
- result += alph_to_pair[temp[i]];
- idx++;
- }
- }
- vector <pair <char, int>> key;
- string tek;
- key_stream >> tek;
- key_stream_out << endl;
- key_stream_out << tek;
- forn(i, tek.size())
- key.push_back(mp(tek[i], i));
- sort(all(key));
- forn(i, result.size() / key.size()) {
- forn(j, key.size()) {
- forn(k, key.size()) {
- int idxx = i * key.size() * key.size() + key[j].second + k * key.size();
- if (idxx < result.size())
- cout << result[idxx];
- }
- }
- }
- return 0;
- }
- ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int main() {
- srand(time(NULL));
- ifstream key_stream("key_2.txt");
- ifstream text_stream("output.txt");
- ofstream text_stream_out("text_2.txt");
- string alph, temp_key;
- key_stream >> alph >> temp_key;
- map <string, string> pair_to_alph;
- string temp[] = { "A", "D", "F", "G", "V", "X" };
- forn(i, 6) {
- forn(j, 6) {
- pair_to_alph[temp[i] + temp[j]] = alph[i * 6 + j];
- }
- }
- string text;
- while (!text_stream.eof())
- text_stream >> text;
- vector <string> result(text.size());
- vector <pair <char, int>> key;
- forn(i, temp_key.size())
- key.push_back(mp(temp_key[i], i));
- sort(all(key));
- int idxx = 0;
- forn(i, result.size() / key.size()) {
- forn(j, key.size()) {
- forn(k, key.size()) {
- int idx = i * key.size() * key.size() + key[j].second + k * key.size();
- if (idx < result.size())
- result[idx] = text[idxx], idxx++;
- }
- }
- }
- for (int i = 0; i < result.size(); i += 2)
- text_stream_out << pair_to_alph[result[i] + result[i + 1]];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement