Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <string>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <clocale>
  9.  
  10. using namespace std;
  11.  
  12. int main() {
  13.     setlocale(LC_CTYPE, "Russian");
  14.     int cp = GetConsoleCP();
  15.     SetConsoleCP(1251);
  16.     SetConsoleCP(cp);
  17.     //SetConsoleOutputCP(1251);
  18.     ifstream in("input.txt");
  19.     ofstream out("output.txt");
  20.     ofstream outKey("Key.txt");
  21.     string CryptText, OpenText;
  22.     string Alph = "абвгдеЄжзийклмнопрстуфхцчшщъыьэю€";
  23.     int m = Alph.size();
  24.     srand(time(NULL));
  25.     int NumberRandomFirstSymbol;
  26.     NumberRandomFirstSymbol = rand() % Alph.size();
  27.     char RandomSymbol;
  28.     RandomSymbol = Alph[NumberRandomFirstSymbol];
  29.     cout << "RandomSymbol = " << RandomSymbol << endl;
  30.     string key;
  31.     key += RandomSymbol;
  32.     while(!in.eof()) {
  33.         string temp;
  34.         getline(in, temp, '\t');
  35.         OpenText += temp;
  36.     }
  37.     for(int i = 0; i < OpenText.size() - 1; i++) {
  38.         if((OpenText[i] >= 'ј') && (OpenText[i] <= 'я')) {
  39.             OpenText[i] += '€' - 'я';
  40.         }
  41.     }
  42.     string FinalOpenText;
  43.     for(int i = 0; i < OpenText.size(); i++) {
  44.         for(int j = 0; j < Alph.size(); j++) {
  45.             if(OpenText[i] == Alph[j]) {
  46.                 FinalOpenText += OpenText[i];
  47.             }
  48.         }
  49.     }
  50.     for(int i = 0; i < FinalOpenText.size() - 1; i++) {
  51.         key += FinalOpenText[i];
  52.     }
  53.     outKey << RandomSymbol;
  54.     cout << "Open Text:  " << FinalOpenText << endl;
  55.     cout << "Key-Word:   " << key << endl;
  56.     int first = 0, second = 0;
  57.     int NumberSymbol = 0;
  58.     for(int i = 0; i < FinalOpenText.size(); i++) {
  59.         for(int j = 0; j < Alph.size(); j++) {
  60.             if(FinalOpenText[i] == Alph[j]) {
  61.                 first = j;
  62.             }
  63.         }
  64.         for(int j = 0; j < Alph.size(); j++) {
  65.             if(key[i] == Alph[j]) {
  66.                 second = j;
  67.             }
  68.         }
  69.         NumberSymbol = ((first + second) % m);
  70.         CryptText += Alph[NumberSymbol];
  71.     }
  72.     cout << "Crypt Text: " << CryptText << endl;
  73.     out << CryptText;
  74.     in.close();
  75.     out.close();
  76.     outKey.close();
  77.     system("pause");
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement