ademosh

4 задание введение в2.0

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