ademosh

8 задание парный шифр

Nov 10th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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[30][2] = { ' ' };
  27. string message;
  28. string key;
  29. string keybuf;
  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. int check = 0;
  41. for (int i = 0; i < ukazi; ++i) {
  42. if (buf == alphaB[i][0]) check = 1;
  43. }
  44. if (check == 0) {
  45. alpha.erase(code(buf), 1);
  46. keybuf+= buf;
  47. ukazi += 1;
  48. }
  49. }
  50. keybuf += ' ';
  51. int iter = 0;
  52. while (!keybuf.empty()) {
  53. char buff = keybuf[0];
  54. char bufs;
  55. if (alpha[0] != ',') {
  56. bufs = alpha[0];
  57. alpha.erase(0, 1);
  58. }
  59. else if (keybuf[1]!=' '){
  60. bufs = keybuf[1];
  61. keybuf.erase(0, 1);
  62. }
  63. else {
  64. bufs = buff;
  65. keybuf.erase(0, 1);
  66. }
  67. keybuf.erase(0, 1);
  68. alphaB[iter][0] = buff;
  69. alphaB[iter][1] = bufs;
  70. iter++;
  71. }
  72.  
  73. for (int i = 0; i < ukazi; ++i) {
  74. cout << alphaB[i][0] << ' ';
  75. }
  76. cout << endl;
  77. for (int i = 0; i < ukazi; ++i) {
  78. cout << alphaB[i][1] << ' ';
  79. }
  80. cout << endl;
  81. while (!message.empty()) {
  82. char buf;
  83. buf = message[0];
  84. message.erase(0, 1);
  85. for (int i = 0; i < ukazi; ++i) {
  86. if (buf == alphaB[i][0]) {
  87. cout << alphaB[i][1];
  88. output<< alphaB[i][1];
  89. break;
  90. }
  91. else if (buf == alphaB[i][1]) {
  92. cout << alphaB[i][0];
  93. output<< alphaB[i][0];
  94. break;
  95. }
  96. if (buf == ' ') {
  97. cout << ' ';
  98. output<< ' ';
  99. break;
  100. }
  101. }
  102.  
  103. }
  104. cout << endl;
  105. system("pause");
  106. return 0;
  107. }
Add Comment
Please, Sign In to add comment