ademosh

Полибий

Oct 28th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 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. char alphaB[6][6] ;
  27.  
  28. string message;
  29. string key ;
  30. getline(start, key);
  31. getline(start, message);
  32. cout << endl;
  33. int o;
  34. int ukazi = 0;
  35. int ukazj = 0;
  36. while (key.length()>0)
  37. {
  38. char buf = key[0];
  39. key.erase(0, 1);
  40. alpha.erase(code(buf), 1);
  41. alphaB[ukazi][ukazj] = buf;
  42. ukazj += 1;
  43. if (ukazj == 6) {
  44. ukazj = 0;
  45. ukazi += 1;
  46. }
  47. }
  48. while (alpha.length() > 0)
  49. {
  50. char buf = alpha[0];
  51. alpha.erase(0, 1);
  52. alphaB[ukazi][ukazj] = buf;
  53. ukazj += 1;
  54. if (ukazj == 6) {
  55. ukazj = 0;
  56. ukazi += 1;
  57. }
  58. }
  59. for (int i = 0; i < 6; ++i) {
  60. for (int j = 0; j < 6; ++j) {
  61. cout << alphaB[i][j] << ' ';
  62. }
  63. cout << endl;
  64. }
  65. cin >> o;
  66. if (o==0)
  67. {
  68. string first;
  69. string second;
  70. for (int i = 0; i < message.length(); ++i)
  71. {
  72. for (int im = 0; im < 6; ++im)
  73. for (int jm = 0; jm < 6; ++jm) {
  74. if (message[i] == alphaB[im][jm]) {
  75. auto f = to_string(im);
  76. auto s = to_string(jm);
  77. first += f;
  78. second += s;
  79. }
  80. }
  81. }
  82. cout << first << endl << second;
  83. first += second;
  84. while (!first.empty())
  85. {
  86. int stroka = (int)first[0] - '0';
  87. first.erase(0, 1);
  88. int stolb = (int)first[0] - '0';
  89. first.erase(0, 1);
  90. output << alphaB[stroka][stolb];
  91. }
  92.  
  93. }
  94. if (o == 1)
  95. {
  96. string buf;
  97. string first;
  98. string second;
  99. for (int i = 0; i < message.length(); ++i)
  100. {
  101. for (int im = 0; im < 6; ++im)
  102. for (int jm = 0; jm < 6; ++jm) {
  103. if (message[i] == alphaB[im][jm]) {
  104. auto f = to_string(im);
  105. auto s = to_string(jm);
  106. buf += f;
  107. buf += s;
  108. }
  109. }
  110. }
  111. int count = buf.length();
  112. count = count/ 2;
  113. for(int i=0;i<count;++i) {
  114. first += buf[0];
  115. buf.erase(0, 1);
  116. }
  117. for (int i = 0; i < count; ++i) {
  118. second += buf[0];
  119. buf.erase(0, 1);
  120. }
  121. while (!first.empty()) {
  122. int stroka = (int)first[0] - '0';
  123. first.erase(0, 1);
  124. int stolb = (int)second[0] - '0';
  125. second.erase(0, 1);
  126. output << alphaB[stroka][stolb];
  127. }
  128. }
  129. system("pause");
  130. return 0;
  131. }
Add Comment
Please, Sign In to add comment