Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <string>
  6. #include <sstream>
  7.  
  8. using namespace std;
  9. const char fname[] = "/Users/markgordienko/Desktop/Без названия.txt";
  10.  
  11. int main()
  12. {
  13.     setlocale(LC_ALL, "Russian");
  14.     char alf[26] = { 'a', 'b', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  15.     char alf1[4] = { ' ','.',',','-' };
  16.     size_t count = 0; //Число символов в файле
  17.     char S;
  18.     ifstream f(fname);
  19.     while (!f.eof())
  20.     {
  21.         f.get(S);
  22.         count++;
  23.     }
  24.     f.close();
  25.     char *S2 = new char[count];
  26.     for (int i = 0; i < count; i++) S2[i] = NULL;
  27.     ifstream f2(fname);
  28.     int i = 0;
  29.  
  30.     while (!f2.eof())
  31.     {
  32.         f2.get(S2[i]);
  33.         i++;
  34.     }
  35.     f2.close();
  36.     cout << "count = " << count << endl;
  37.     cout << "Текст для шифрования: " << endl;
  38.     for (int i = 0; i < count; i++)
  39.     {
  40.         cout << S2[i];
  41.     }
  42.     cout << endl;
  43.     char *shifr = new char[count];
  44.     char K[5];
  45.     cout << "Введите ключевое слово: " << endl;
  46.     cin >> K;
  47.     char *K1 = new char[count];
  48.     for (int i = 0; i < count/5 + 1; i++)
  49.     {
  50.         for (int j = 0; j < count; j++)
  51.         {
  52.             for (int k= 0; k < 5; k++)
  53.             {
  54.                 K1[i * 5+k] = K[k];
  55.             }
  56.         }
  57.     }
  58.     for (int i = 0; i < count; i++)
  59.     {
  60.         cout << K1[i];
  61.     }
  62.     /*for (int i = 0; i < count; i++)
  63.     {
  64.         for (int s = 0; s <= 26; s++)
  65.         {
  66.             if (S2[i] == '-')
  67.             {
  68.                 shifr[i] = S2[i];
  69.             }
  70.             if (S2[i] == ' ')
  71.             {
  72.                 shifr[i] = S2[i];
  73.             }
  74.             if (S2[i] == '\n')
  75.             {
  76.                 shifr[i] = S2[i];
  77.             }
  78.             if (S2[i] == '\t')
  79.             {
  80.                 shifr[i] = S2[i];
  81.             }
  82.             if (S2[i] == ',')
  83.             {
  84.                 shifr[i] = S2[i];
  85.             }
  86.             if (S2[i] == '.')
  87.             {
  88.                 shifr[i] = S2[i];
  89.             }
  90.             if (S2[i] == alf[s])
  91.             {
  92.                 int u = () % 26;
  93.                 shifr[i] = alf[u];
  94.             }
  95.  
  96.         }
  97.  
  98.     }
  99.     cout << "Зашифрованный текст: " << endl;
  100.     for (int i = 0; i < count - 1; i++)
  101.     {
  102.         cout << "shifr[" << i << "]" << shifr[i] << endl;
  103.     }
  104.     cout << endl;
  105.  
  106. */
  107.     //char *rasshifr = new char[count];
  108.     //delete[] shifr;
  109.     //delete[] rasshifr;
  110.     cout << endl;
  111.     return(0);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement