ademosh

Вижнер

Oct 28th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "pch.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7.  
  8.  
  9. using namespace std;
  10. //Объявляем массив символов русского и английского алфавита
  11. string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
  12. int code(char str)
  13. {
  14. for (int i = 0; i < 33; i++) {
  15. if (str == alpha[i])
  16. return i;
  17. }
  18. }
  19.  
  20. int main() {
  21. system("chcp 1251");
  22. system("cls");
  23. setlocale(LC_ALL, "Russian");
  24. ifstream start("start.txt");
  25. ofstream output("out.txt");
  26. string alphaB[33][33] = { "" };
  27. for (int i = 0; i < 33; ++i)
  28. {
  29. int j = 0;
  30. int shift = i;
  31. cout << shift << endl;
  32. while (j < 33)
  33. {
  34. if (shift == 33) shift -= 33;
  35. alphaB[i][j] = alpha[shift];
  36. shift++;
  37. j++;
  38. }
  39. }
  40. for (int i = 0; i < 33; ++i)
  41. {
  42. for (int j = 0; j < 33; ++j)
  43. cout << alphaB[i][j] << ' ';
  44. cout << endl;
  45. }
  46. string message;
  47. string key ;
  48. getline(start, key);
  49. getline(start, message);
  50. cout << endl;
  51. int o;
  52. cin >> o;
  53.  
  54. if (o == 0)
  55. {
  56. int k = 0;
  57. int cod;
  58. int resultcode = 0;
  59. string out;
  60. for (int i = 0; i < message.length(); i += 1)
  61. {
  62. if (k >= key.length())
  63. k = 0;
  64.  
  65. resultcode += code(message[i]);
  66.  
  67. resultcode += code(key[k]);
  68. //if (resultcode >= 66) resultcode -= 33;
  69. //if (resultcode >= 66) resultcode -= 33;
  70. int stroka = abs(code(message[i]));
  71. int stolb = abs(code(key[k]));
  72. cout << message[i] << ' ' << stroka << ' ' << stolb << ' ' << endl;
  73. output << alphaB[stroka][stolb];
  74. resultcode = 0;
  75. k++;
  76. }
  77.  
  78.  
  79. }
  80. if (o == 1)
  81. {
  82. int k = 0;
  83. int cod;
  84. int resultcode = 0;
  85. string out;
  86. for (int i = 0; i < message.length(); i += 1)
  87. {
  88. if (k >= key.length())
  89. k = 0;
  90.  
  91. resultcode += code(message[i]);
  92.  
  93. resultcode += code(key[k]);
  94. //if (resultcode >= 66) resultcode -= 33;
  95. //if (resultcode >= 66) resultcode -= 33;
  96. int stroka = abs(code(message[i]));
  97. int stolb = abs(code(key[k]));
  98. for (int j = 0; j < 32; ++j)
  99. {
  100. if (alphaB[j][stolb] == alphaB[code(message[i])][0]) {
  101. cout << j << ' ' << stolb << ' ' << code(message[i]) << alphaB[j][stolb]<<' '<< endl;
  102. output << alphaB[j][0];
  103. break;
  104. }
  105. }
  106. resultcode = 0;
  107. k++;
  108. }
  109.  
  110. }
  111. system("pause");
  112. return 0;
  113. }
Add Comment
Please, Sign In to add comment